aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-07-30 13:02:49 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-07-30 13:02:49 +0000
commit82254eb5e19732856c7d5f493fc86145754021ed (patch)
treebafe8db2be9fcaf2faa566c3e268b60f9b08fb2d /engine/lib
parent66b1c80db62648374ac6112f59c4b6fe2bffac72 (diff)
downloadelgg-82254eb5e19732856c7d5f493fc86145754021ed.tar.gz
elgg-82254eb5e19732856c7d5f493fc86145754021ed.tar.bz2
Introducing url handlers for extenders.
git-svn-id: https://code.elgg.org/elgg/trunk@1598 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/annotations.php50
-rw-r--r--engine/lib/extender.php66
-rw-r--r--engine/lib/metadata.php51
3 files changed, 90 insertions, 77 deletions
diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php
index 255e8a9b0..5d2029591 100644
--- a/engine/lib/annotations.php
+++ b/engine/lib/annotations.php
@@ -683,47 +683,21 @@
{
$id = (int)$id;
- global $CONFIG;
-
if ($extender = get_annotation($id)) {
-
- $view = elgg_get_viewtype();
-
- $guid = $extender->entity_guid;
- $type = $extender->type;
-
- $url = "";
-
- /*if (isset($CONFIG->entity_url_handler[$entity->getType()][$entity->getSubType()])) {
- $function = $CONFIG->entity_url_handler[$entity->getType()][$entity->getSubType()];
- if (is_callable($function)) {
- $url = $function($entity);
- }
- }
- if (isset($CONFIG->entity_url_handler[$entity->getType()]['all'])) {
- $function = $CONFIG->entity_url_handler[$entity->getType()]['all'];
- if (is_callable($function)) {
- $url = $function($entity);
- }
- }
- if (isset($CONFIG->entity_url_handler['all']['all'])) {
- $function = $CONFIG->entity_url_handler['all']['all'];
- if (is_callable($function)) {
- $url = $function($entity);
- }
- }*/
-
-
- if ($url == "") {
- $nameid = $extender->id;
- if ($type == 'volatile')
- $nameid== $extender->name;
- $url = $CONFIG->wwwroot . "$view/$guid/$type/$nameid/";
- }
- return $url;
-
+ return get_extender_url($extender);
}
return false;
+ }
+
+
+ /**
+ * Register an annotation url handler.
+ *
+ * @param string $function_name The function.
+ * @param string $extender_name The name, default 'all'.
+ */
+ function register_annotation_url_handler($function_name, $extender_name = "all") {
+ return register_extender_url_handler($function_name, 'annotation', $extender_name);
}
/** Register the hook */
diff --git a/engine/lib/extender.php b/engine/lib/extender.php
index 8af18c38c..81d44a091 100644
--- a/engine/lib/extender.php
+++ b/engine/lib/extender.php
@@ -352,6 +352,72 @@
// Trigger plugin hooks
return trigger_plugin_hook('permissions_check',$type,array('entity' => $entity, 'user' => $user),false);
+ }
+
+ /**
+ * Sets the URL handler for a particular extender type and name.
+ * It is recommended that you do not call this directly, instead use one of the wrapper functions in the
+ * subtype files.
+ *
+ * @param string $function_name The function to register
+ * @param string $extender_type Extender type
+ * @param string $extender_name The name of the extender
+ * @return true|false Depending on success
+ */
+ function register_extender_url_handler($function_name, $extender_type = "all", $extender_name = "all") {
+ global $CONFIG;
+
+ if (!is_callable($function_name)) return false;
+
+ if (!isset($CONFIG->extender_url_handler)) {
+ $CONFIG->extender_url_handler = array();
+ }
+ 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;
+
+ return true;
+
+ }
+
+ /**
+ * Get the URL of a given elgg extender.
+ * Used by get_annotation_url and get_metadata_url.
+ *
+ * @param ElggExtender $extender
+ */
+ function get_extender_url(ElggExtender $extender)
+ {
+ 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);
+ }
+
+ if ($url == "") {
+ $nameid = $extender->id;
+ if ($type == 'volatile')
+ $nameid== $extender->name;
+ $url = $CONFIG->wwwroot . "$view/$guid/$type/$nameid/";
+ }
+ return $url;
}
/** Register the hook */
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index 14e141ec4..70f563d25 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -744,49 +744,22 @@
{
$id = (int)$id;
- global $CONFIG;
-
if ($extender = get_metadata($id)) {
-
- $view = elgg_get_viewtype();
-
- $guid = $extender->entity_guid;
- $type = $extender->type;
-
- $url = "";
-
- /*if (isset($CONFIG->entity_url_handler[$entity->getType()][$entity->getSubType()])) {
- $function = $CONFIG->entity_url_handler[$entity->getType()][$entity->getSubType()];
- if (is_callable($function)) {
- $url = $function($entity);
- }
- }
- if (isset($CONFIG->entity_url_handler[$entity->getType()]['all'])) {
- $function = $CONFIG->entity_url_handler[$entity->getType()]['all'];
- if (is_callable($function)) {
- $url = $function($entity);
- }
- }
- if (isset($CONFIG->entity_url_handler['all']['all'])) {
- $function = $CONFIG->entity_url_handler['all']['all'];
- if (is_callable($function)) {
- $url = $function($entity);
- }
- }*/
-
-
- if ($url == "") {
- $nameid = $extender->id;
- if ($type == 'volatile')
- $nameid== $extender->name;
- $url = $CONFIG->wwwroot . "$view/$guid/$type/$nameid/";
- }
- return $url;
-
+ return get_extender_url($extender);
}
return false;
- }
+ }
+ /**
+ * Register a metadata url handler.
+ *
+ * @param string $function_name The function.
+ * @param string $extender_name The name, default 'all'.
+ */
+ function register_metadata_url_handler($function_name, $extender_name = "all") {
+ return register_extender_url_handler($function_name, 'metadata', $extender_name);
+ }
+
/** Register the hook */
register_plugin_hook("export", "all", "export_metadata_plugin_hook", 2);
?> \ No newline at end of file