diff options
-rw-r--r-- | engine/lib/elgglib.php | 46 | ||||
-rw-r--r-- | engine/lib/metastrings.php | 20 |
2 files changed, 64 insertions, 2 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index cc7fbf209..f1ddb2472 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -241,7 +241,7 @@ * @param ElggEntity $entity The entity to display
* @param string $viewtype Optionally, the type of view that we're using (most commonly 'default')
* @param boolean $full Determines whether or not to display the full version of an object, or a smaller version for use in aggregators etc
- * @param boolean $debug If set to true, elgg_view will bypass any specified alternative template handler; by default, it will hand off to this if requested (see set_template_handler)
+ * @param boolean $bypass If set to true, elgg_view will bypass any specified alternative template handler; by default, it will hand off to this if requested (see set_template_handler)
* @param boolean $debug If set to true, the viewer will complain if it can't find a view
* @return string HTML (etc) to display
*/
@@ -290,7 +290,49 @@ ), $viewtype, $bypass, $debug);
}
}
-
+
+ /**
+ * When given an annotation, views it intelligently.
+ *
+ * This function expects annotation views to be of the form annotation/name, where name
+ * is the type of annotation.
+ *
+ * @param ElggAnnotation $annotation The annotation to display
+ * @param string $viewtype Optionally, the type of view that we're using (most commonly 'default')
+ * @param boolean $full Determines whether or not to display the full version of an object, or a smaller version for use in aggregators etc
+ * @param boolean $bypass If set to true, elgg_view will bypass any specified alternative template handler; by default, it will hand off to this if requested (see set_template_handler)
+ * @param boolean $debug If set to true, the viewer will complain if it can't find a view
+ * @return string HTML (etc) to display
+ */
+ function elgg_view_annotation(ElggAnnotation $annotation, $viewtype = "", $bypass = true, $debug = false) {
+
+ global $autofeed;
+ $autofeed = true;
+
+ $view = $annotation->view;
+ if (is_string($view)) {
+ return elgg_view($view,array('annotation' => $annotation), $viewtype, $bypass, $debug);
+ }
+
+ $name = $annotation->name;
+ $intname = (int) $name;
+ if ("{$intname}" == "{$name}") {
+ $name = get_metastring($intname);
+ }
+ if (empty($name)) { return ""; }
+
+ if (elgg_view_exists("annotation/{$name}")) {
+ return elgg_view("annotation/{$name}",array(
+ 'annotation' => $annotation,
+ ), $viewtype, $bypass, $debug);
+ } else {
+ return elgg_view("annotation/default",array(
+ 'annotation' => $annotation,
+ ), $viewtype, $bypass, $debug);
+ }
+ }
+
+
/**
* Returns a view of a list of entities, plus navigation. It is intended that this function
* be called from other wrapper functions.
diff --git a/engine/lib/metastrings.php b/engine/lib/metastrings.php index aaa199e03..74668ec81 100644 --- a/engine/lib/metastrings.php +++ b/engine/lib/metastrings.php @@ -28,6 +28,26 @@ return $row->id; return false; + }
+
+ /**
+ * When given an ID, returns the corresponding metastring
+ *
+ * @param int $id Metastring ID
+ * @return string Metastring
+ */
+ function get_metastring($id) {
+
+ global $CONFIG;
+
+ $id = (int) $id;
+
+ $row = get_data_row("SELECT * from {$CONFIG->dbprefix}metastrings where id='$id' limit 1");
+ if ($row)
+ return $row->string;
+
+ return false;
+
} /** |