diff options
-rw-r--r-- | engine/lib/extender.php | 49 | ||||
-rw-r--r-- | engine/lib/relationships.php | 77 |
2 files changed, 101 insertions, 25 deletions
diff --git a/engine/lib/extender.php b/engine/lib/extender.php index 20b1750f5..e444a4d55 100644 --- a/engine/lib/extender.php +++ b/engine/lib/extender.php @@ -375,7 +375,7 @@ if (!isset($CONFIG->extender_url_handler[$extender_type])) { $CONFIG->extender_url_handler[$extender_type] = array(); } - $CONFIG->entity_url_handler[$extender_type][$extender_name] = $function_name; + $CONFIG->extender_url_handler[$extender_type][$extender_name] = $function_name; return true; @@ -391,33 +391,32 @@ { global $CONFIG; - $view = elgg_get_viewtype(); - $guid = $extender->entity_guid; - $type = $extender->type; - - $url = ""; - - $function = ""; - if (isset($CONFIG->extender_url_handler[$type][$extender->name])) - $function = $CONFIG->extender_url_handler[$type][$extender->name]; - if (isset($CONFIG->extender_url_handler[$type]['all'])) - $function = $CONFIG->extender_url_handler[$type]['all']; - if (isset($CONFIG->extender_url_handler['all']['all'])) - $function = $CONFIG->extender_url_handler['all']['all']; - - if (is_callable($function)) { - $url = $function($extender); - } + $guid = $extender->entity_guid; + $type = $extender->type; + + $url = ""; + + $function = ""; + if (isset($CONFIG->extender_url_handler[$type][$extender->name])) + $function = $CONFIG->extender_url_handler[$type][$extender->name]; + if (isset($CONFIG->extender_url_handler[$type]['all'])) + $function = $CONFIG->extender_url_handler[$type]['all']; + if (isset($CONFIG->extender_url_handler['all']['all'])) + $function = $CONFIG->extender_url_handler['all']['all']; - if ($url == "") { - $nameid = $extender->id; - if ($type == 'volatile') - $nameid== $extender->name; - $url = $CONFIG->wwwroot . "export/$view/$guid/$type/$nameid/"; - } - return $url; + if (is_callable($function)) { + $url = $function($extender); + } + + if ($url == "") { + $nameid = $extender->id; + if ($type == 'volatile') + $nameid== $extender->name; + $url = $CONFIG->wwwroot . "export/$view/$guid/$type/$nameid/"; + } + return $url; }
/** Register the hook */ diff --git a/engine/lib/relationships.php b/engine/lib/relationships.php index 8e9768a8c..ffb2d1ee4 100644 --- a/engine/lib/relationships.php +++ b/engine/lib/relationships.php @@ -107,6 +107,16 @@ { return delete_relationship($this->id); } + + /** + * Get a URL for this relationship. + * + * @return string + */ + public function getURL() + { + return get_relationship_url($this->id); + } // EXPORTABLE INTERFACE //////////////////////////////////////////////////////////// @@ -532,6 +542,73 @@ } + /** + * Sets the URL handler for a particular relationship type + * + * @param string $function_name The function to register + * @param string $relationship_type The relationship type. + * @return true|false Depending on success + */ + function register_relationship_url_handler($function_name, $relationship_type = "all") { + global $CONFIG; + + if (!is_callable($function_name)) return false; + + if (!isset($CONFIG->relationship_url_handler)) { + $CONFIG->relationship_url_handler = array(); + } + + $CONFIG->relationship_url_handler[$relationship_type] = $function_name; + + return true; + + } + + /** + * Get the url for a given relationship. + * + * @param unknown_type $id + * @return unknown + */ + function get_relationship_url($id) + { + global $CONFIG; + + $id = (int)$id; + + if ($relationship = get_relationship($id)) + { + $view = elgg_get_viewtype(); + + $guid = $relationship->guid_one; + $type = $relationship->relationship; + + $url = ""; + + $function = ""; + if (isset($CONFIG->relationship_url_handler[$type])) + $function = $CONFIG->relationship_url_handler[$type]; + if (isset($CONFIG->relationship_url_handler['all'])) + $function = $CONFIG->relationship_url_handler['all']; + + if (is_callable($function)) { + $url = $function($relationship); + } + + if ($url == "") { + + $nameid = $relationship->id; + + $url = $CONFIG->wwwroot . "export/$view/$guid/relationship/$nameid/"; + } + + return $url; + + } + + return false; + } + /**** HELPER FUNCTIONS FOR RELATIONSHIPS OF TYPE 'ATTACHED' ****/ /** |