aboutsummaryrefslogtreecommitdiff
path: root/mod/sitepages/sitepages_functions.php
diff options
context:
space:
mode:
Diffstat (limited to 'mod/sitepages/sitepages_functions.php')
-rw-r--r--mod/sitepages/sitepages_functions.php107
1 files changed, 103 insertions, 4 deletions
diff --git a/mod/sitepages/sitepages_functions.php b/mod/sitepages/sitepages_functions.php
index 7ffe8df63..0341b590b 100644
--- a/mod/sitepages/sitepages_functions.php
+++ b/mod/sitepages/sitepages_functions.php
@@ -10,10 +10,6 @@
*/
-function sitepages_parse_frontpage($contents){
- echo htmlspecialchars_decode($contents, ENT_NOQUOTES);
-}
-
/**
* Returns a single object that holds information about
* customizations for the $section site page. The object guid
@@ -115,6 +111,109 @@ function sitepages_get_page_content($page_type) {
return $content;
}
+
+/**
+ * Used to determine how to handle special non-static keywords.
+ *
+ * @param unknown_type $matches
+ * @return html
+ */
+function sitepages_parse_view_match($matches) {
+ $keyword = $matches[0];
+ $type = trim($matches[1]);
+ $params_string = trim($matches[2]);
+
+ switch ($type) {
+ case 'entity':
+ $options = sitepages_keywords_parse_entity_params($params_string);
+ // must use this lower-level function because I missed refactoring
+ // the list entity functions for relationships.
+ // (which, since you're here, is the only function that runs through all
+ // possible options for elgg_get_entities*() functions...)
+ $entities = elgg_get_entities_from_relationship($options);
+ $content = elgg_view_entity_list($entities, count($entities), $options['offset'],
+ $options['limit'], $options['full_view'], $options['view_type_toggle'], $options['pagination']);
+ break;
+
+ case 'view':
+ // parses this into an acceptable array for $vars.
+ $info = sitepages_keywords_parse_view_params($params_string);
+ $content = elgg_view($info['view'], $info['vars']);
+
+ break;
+
+ }
+
+ return $content;
+}
+
+/**
+ * Creates an array from a "name=value, name1=value2" string.
+ *
+ * @param $string
+ * @return array
+ */
+function sitepages_keywords_tokenize_params($string) {
+ $pairs = array_map('trim', explode(',', $string));
+
+ $params = array();
+
+ foreach ($pairs as $pair) {
+ list($name, $value) = explode('=', $pair);
+
+ $name = trim($name);
+ $value = trim($value);
+ $params[$name] = $value;
+ }
+
+ return $params;
+}
+
+/**
+ *
+ * @param $string
+ * @return unknown_type
+ */
+function sitepages_keywords_parse_view_params($string) {
+ $vars = sitepages_keywords_tokenize_params($string);
+
+ // the first element key is the view
+ $var_keys = array_keys($vars);
+ $view = $var_keys[0];
+
+ $info = array(
+ 'view' => $view,
+ 'vars' => $vars
+ );
+
+ return $info;
+
+}
+
+/**
+ * Returns an options array suitable for using in elgg_get_entities()
+ *
+ * @param string $string "name=value, name2=value2"
+ * @return array
+ */
+function sitepages_keywords_parse_entity_params($string) {
+ $params = sitepages_keywords_tokenize_params($string);
+
+ // handle some special cases
+ if (isset($params['owner'])) {
+ if ($user = get_user_by_username($params['owner'])) {
+ $options['owner_guid'] = $user->getGUID();
+ }
+ }
+
+ // @todo probably need to add more for
+ // group -> container_guid, etc
+
+ return $params;
+}
+
+
+
/**
* Utility object to store site page information.
*/