aboutsummaryrefslogtreecommitdiff
path: root/mod/sitepages/sitepages_functions.php
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-03-25 22:00:44 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-03-25 22:00:44 +0000
commitc2e2d3ae222a55086bed95d897c6e8c50b066c37 (patch)
tree9039f6be684ab133c13e5f4cb8e36ff37f2aec5a /mod/sitepages/sitepages_functions.php
parentd86408d2662b961645b4ed4cdbd37d5150819cf4 (diff)
downloadelgg-c2e2d3ae222a55086bed95d897c6e8c50b066c37.tar.gz
elgg-c2e2d3ae222a55086bed95d897c6e8c50b066c37.tar.bz2
Converting all line endings to unix style.
git-svn-id: http://code.elgg.org/elgg/trunk@5512 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/sitepages/sitepages_functions.php')
-rw-r--r--mod/sitepages/sitepages_functions.php448
1 files changed, 224 insertions, 224 deletions
diff --git a/mod/sitepages/sitepages_functions.php b/mod/sitepages/sitepages_functions.php
index 20e7cb0b6..bc14d1a54 100644
--- a/mod/sitepages/sitepages_functions.php
+++ b/mod/sitepages/sitepages_functions.php
@@ -1,225 +1,225 @@
-<?php
-/**
- * Helper functions for Site Pages.
- *
- * @package SitePages
- * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
- * @author Curverider Ltd
- * @copyright Curverider Ltd 2008-2010
- * @link http://elgg.org/
- */
-
-
-/**
- * Returns a single object that holds information about
- * customizations for the $section site page. The object guid
- * is stored as private data on the site entity. This allows the pages
- * to still be searchable as standard entities.
- *
- * @param $type
- * @return mixed ElggSitePage on success, FALSE on fail
- */
-function sitepages_get_sitepage_object($page_type) {
- global $CONFIG;
-
- $page_guid = get_private_setting($CONFIG->site->getGUID(), "sitepages:$page_type");
- $sitepage = get_entity($page_guid);
-
- if ($sitepage instanceof ElggSitePage || $sitepage->page_type == $page_type) {
- return $sitepage;
- }
-
- return FALSE;
-}
-
-/**
- * Creates a site page object.
- *
- * @param str $page_type
- * @return mixed ElggSitePage on success, FALSE on fail.
- */
-function sitepages_create_sitepage_object($page_type) {
- global $CONFIG;
-
- $sitepage = new ElggSitePage();
- $sitepage->page_type = $page_type;
- $sitepage->access_id = ACCESS_PUBLIC;
- $sitepage->save();
-
- if ($sitepage->save() && set_private_setting($CONFIG->site->getGUID(), "sitepages:$page_type", $sitepage->getGUID())) {
- return $sitepage;
- }
-
- return FALSE;
-}
-
-/**
- * Assembles html for edit sections of site pages.
- *
- * @param str $section
- * @return str html
- */
-function sitepages_get_edit_section_content($page_type) {
- set_context('admin');
-
- $keywords = '';
-
- $title = elgg_view_title(elgg_echo('sitepages'));
- $menu = elgg_view('sitepages/menu', array('page_type' => $page_type));
-
- switch ($page_type) {
- case 'front':
- $view = 'sitepages/forms/editfront';
- $keywords = elgg_view('sitepages/keywords');
- break;
-
- case 'seo':
- $view = 'sitepages/forms/editmeta';
- break;
-
- default:
- $view = 'sitepages/forms/edit';
- break;
-
- }
-
- $form .= elgg_view($view, array('page_type' => $page_type));
- $body = $title . $menu . $form;
-
- $content = elgg_view_layout('one_column_with_sidebar', $body, $keywords);
- return $content;
-}
-
-/**
- * Assembles html for displaying site pages
- *
- * @param string $page_type
- * @return string Formatted html
- */
-function sitepages_get_page_content($page_type) {
- $body = elgg_view_title(elgg_echo("sitepages:". strtolower($page_type)));
-
- $sitepage = sitepages_get_sitepage_object($page_type);
-
- if ($sitepage) {
- $body .= elgg_view('page_elements/elgg_content', array('body' => $sitepage->description));
- } else {
- $body .= elgg_view('page_elements/elgg_content', array('body' => elgg_echo('sitepages:notset')));
- }
-
- $content = elgg_view_layout('one_column_with_sidebar', $body);
- 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'])) {
- $params['owner_guid'] = $user->getGUID();
- }
- }
-
- // @todo probably need to add more for
- // group -> container_guid, etc
- return $params;
-}
-
-
-
-/**
- * Utility object to store site page information.
- */
-class ElggSitePage extends ElggObject {
- public function initialise_attributes() {
- parent::initialise_attributes();
-
- $this->attributes['subtype'] = 'sitepages_page';
- }
+<?php
+/**
+ * Helper functions for Site Pages.
+ *
+ * @package SitePages
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008-2010
+ * @link http://elgg.org/
+ */
+
+
+/**
+ * Returns a single object that holds information about
+ * customizations for the $section site page. The object guid
+ * is stored as private data on the site entity. This allows the pages
+ * to still be searchable as standard entities.
+ *
+ * @param $type
+ * @return mixed ElggSitePage on success, FALSE on fail
+ */
+function sitepages_get_sitepage_object($page_type) {
+ global $CONFIG;
+
+ $page_guid = get_private_setting($CONFIG->site->getGUID(), "sitepages:$page_type");
+ $sitepage = get_entity($page_guid);
+
+ if ($sitepage instanceof ElggSitePage || $sitepage->page_type == $page_type) {
+ return $sitepage;
+ }
+
+ return FALSE;
+}
+
+/**
+ * Creates a site page object.
+ *
+ * @param str $page_type
+ * @return mixed ElggSitePage on success, FALSE on fail.
+ */
+function sitepages_create_sitepage_object($page_type) {
+ global $CONFIG;
+
+ $sitepage = new ElggSitePage();
+ $sitepage->page_type = $page_type;
+ $sitepage->access_id = ACCESS_PUBLIC;
+ $sitepage->save();
+
+ if ($sitepage->save() && set_private_setting($CONFIG->site->getGUID(), "sitepages:$page_type", $sitepage->getGUID())) {
+ return $sitepage;
+ }
+
+ return FALSE;
+}
+
+/**
+ * Assembles html for edit sections of site pages.
+ *
+ * @param str $section
+ * @return str html
+ */
+function sitepages_get_edit_section_content($page_type) {
+ set_context('admin');
+
+ $keywords = '';
+
+ $title = elgg_view_title(elgg_echo('sitepages'));
+ $menu = elgg_view('sitepages/menu', array('page_type' => $page_type));
+
+ switch ($page_type) {
+ case 'front':
+ $view = 'sitepages/forms/editfront';
+ $keywords = elgg_view('sitepages/keywords');
+ break;
+
+ case 'seo':
+ $view = 'sitepages/forms/editmeta';
+ break;
+
+ default:
+ $view = 'sitepages/forms/edit';
+ break;
+
+ }
+
+ $form .= elgg_view($view, array('page_type' => $page_type));
+ $body = $title . $menu . $form;
+
+ $content = elgg_view_layout('one_column_with_sidebar', $body, $keywords);
+ return $content;
+}
+
+/**
+ * Assembles html for displaying site pages
+ *
+ * @param string $page_type
+ * @return string Formatted html
+ */
+function sitepages_get_page_content($page_type) {
+ $body = elgg_view_title(elgg_echo("sitepages:". strtolower($page_type)));
+
+ $sitepage = sitepages_get_sitepage_object($page_type);
+
+ if ($sitepage) {
+ $body .= elgg_view('page_elements/elgg_content', array('body' => $sitepage->description));
+ } else {
+ $body .= elgg_view('page_elements/elgg_content', array('body' => elgg_echo('sitepages:notset')));
+ }
+
+ $content = elgg_view_layout('one_column_with_sidebar', $body);
+ 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'])) {
+ $params['owner_guid'] = $user->getGUID();
+ }
+ }
+
+ // @todo probably need to add more for
+ // group -> container_guid, etc
+ return $params;
+}
+
+
+
+/**
+ * Utility object to store site page information.
+ */
+class ElggSitePage extends ElggObject {
+ public function initialise_attributes() {
+ parent::initialise_attributes();
+
+ $this->attributes['subtype'] = 'sitepages_page';
+ }
} \ No newline at end of file