aboutsummaryrefslogtreecommitdiff
path: root/mod/externalpages
diff options
context:
space:
mode:
Diffstat (limited to 'mod/externalpages')
-rw-r--r--mod/externalpages/actions/edit.php35
-rw-r--r--mod/externalpages/languages/en.php27
-rw-r--r--mod/externalpages/manifest.xml15
-rw-r--r--mod/externalpages/start.php102
-rw-r--r--mod/externalpages/views/default/admin/appearance/expages.php10
-rw-r--r--mod/externalpages/views/default/expages/menu.php23
-rw-r--r--mod/externalpages/views/default/expages/wrapper.php16
-rw-r--r--mod/externalpages/views/default/forms/expages/edit.php58
8 files changed, 286 insertions, 0 deletions
diff --git a/mod/externalpages/actions/edit.php b/mod/externalpages/actions/edit.php
new file mode 100644
index 000000000..184aa3d82
--- /dev/null
+++ b/mod/externalpages/actions/edit.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * Elgg external pages: create or update
+ *
+ */
+
+// Get input data and don't filter the content
+$contents = get_input('expagescontent', '', false);
+$type = get_input('content_type');
+$guid = get_input('guid');
+
+if ($guid) {
+ // update
+ $expages = get_entity($guid);
+ if (!$expages) {
+ register_error(elgg_echo("expages:error"));
+ forward(REFERER);
+ }
+} else {
+ // create
+ $expages = new ElggObject();
+ $expages->subtype = $type;
+}
+
+$expages->owner_guid = elgg_get_logged_in_user_guid();
+$expages->access_id = ACCESS_PUBLIC;
+$expages->title = $type;
+$expages->description = $contents;
+if (!$expages->save()) {
+ register_error(elgg_echo("expages:error"));
+ forward(REFERER);
+}
+
+system_message(elgg_echo("expages:posted"));
+forward(REFERER);
diff --git a/mod/externalpages/languages/en.php b/mod/externalpages/languages/en.php
new file mode 100644
index 000000000..5f0f4ad7b
--- /dev/null
+++ b/mod/externalpages/languages/en.php
@@ -0,0 +1,27 @@
+<?php
+/**
+ * External pages English language file
+ */
+
+$english = array(
+
+ /**
+ * Menu items and titles
+ */
+ 'expages' => "Site pages",
+ 'admin:appearance:expages' => "Site Pages",
+ 'expages:about' => "About",
+ 'expages:terms' => "Terms",
+ 'expages:privacy' => "Privacy",
+ 'expages:contact' => "Contact",
+
+ 'expages:notset' => "This page has not been set up yet.",
+
+ /**
+ * Status messages
+ */
+ 'expages:posted' => "Your page was successfully updated.",
+ 'expages:error' => "Unable to save this page.",
+);
+
+add_translation("en", $english);
diff --git a/mod/externalpages/manifest.xml b/mod/externalpages/manifest.xml
new file mode 100644
index 000000000..f2aef09f3
--- /dev/null
+++ b/mod/externalpages/manifest.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8">
+ <name>Site Pages</name>
+ <author>Core developers</author>
+ <version>1.8</version>
+ <category>bundled</category>
+ <description>Create simple web pages for about, contact, privacy, and terms.</description>
+ <website>http://www.elgg.org/</website>
+ <copyright>See COPYRIGHT.txt</copyright>
+ <license>GNU General Public License version 2</license>
+ <requires>
+ <type>elgg_release</type>
+ <version>1.8</version>
+ </requires>
+</plugin_manifest>
diff --git a/mod/externalpages/start.php b/mod/externalpages/start.php
new file mode 100644
index 000000000..f0ffa6b9d
--- /dev/null
+++ b/mod/externalpages/start.php
@@ -0,0 +1,102 @@
+<?php
+/**
+ * Plugin for creating web pages for your site
+ */
+
+elgg_register_event_handler('init', 'system', 'expages_init');
+
+function expages_init() {
+
+ // Register a page handler, so we can have nice URLs
+ elgg_register_page_handler('about', 'expages_page_handler');
+ elgg_register_page_handler('terms', 'expages_page_handler');
+ elgg_register_page_handler('privacy', 'expages_page_handler');
+ elgg_register_page_handler('expages', 'expages_page_handler');
+
+ // Register public external pages
+ elgg_register_plugin_hook_handler('public_pages', 'walled_garden', 'expages_public');
+
+ // add a menu item for the admin edit page
+ elgg_register_admin_menu_item('configure', 'expages', 'appearance');
+
+ // add footer links
+ expages_setup_footer_menu();
+
+ // register action
+ $actions_base = elgg_get_plugins_path() . 'externalpages/actions';
+ elgg_register_action("expages/edit", "$actions_base/edit.php", 'admin');
+}
+
+/**
+ * Extend the public pages range
+ *
+ */
+function expages_public($hook, $handler, $return, $params){
+ $pages = array('about', 'terms', 'privacy');
+ return array_merge($pages, $return);
+}
+
+/**
+ * Setup the links to site pages
+ */
+function expages_setup_footer_menu() {
+ $pages = array('about', 'terms', 'privacy');
+ foreach ($pages as $page) {
+ $url = "$page";
+ $wg_item = new ElggMenuItem($page, elgg_echo("expages:$page"), $url);
+ elgg_register_menu_item('walled_garden', $wg_item);
+
+ $footer_item = clone $wg_item;
+ elgg_register_menu_item('footer', $footer_item);
+ }
+}
+
+/**
+ * External pages page handler
+ *
+ * @param array $page URL segements
+ * @param string $handler Handler identifier
+ * @return bool
+ */
+function expages_page_handler($page, $handler) {
+ if ($handler == 'expages') {
+ expages_url_forwarder($page[1]);
+ }
+ $type = strtolower($handler);
+
+ $title = elgg_echo("expages:$type");
+ $header = elgg_view_title($title);
+
+ $object = elgg_get_entities(array(
+ 'type' => 'object',
+ 'subtype' => $type,
+ 'limit' => 1,
+ ));
+ if ($object) {
+ $content .= elgg_view('output/longtext', array('value' => $object[0]->description));
+ } else {
+ $content .= elgg_echo("expages:notset");
+ }
+ $content = elgg_view('expages/wrapper', array('content' => $content));
+
+ if (elgg_is_logged_in() || !elgg_get_config('walled_garden')) {
+ $body = elgg_view_layout('one_sidebar', array('title' => $title, 'content' => $content));
+ echo elgg_view_page($title, $body);
+ } else {
+ elgg_load_css('elgg.walled_garden');
+ $body = elgg_view_layout('walled_garden', array('content' => $header . $content));
+ echo elgg_view_page($title, $body, 'walled_garden');
+ }
+ return true;
+}
+
+/**
+ * Forward to the new style of URLs
+ *
+ * @param string $page
+ */
+function expages_url_forwarder($page) {
+ global $CONFIG;
+ $url = "{$CONFIG->wwwroot}{$page}";
+ forward($url);
+}
diff --git a/mod/externalpages/views/default/admin/appearance/expages.php b/mod/externalpages/views/default/admin/appearance/expages.php
new file mode 100644
index 000000000..6a5a521a5
--- /dev/null
+++ b/mod/externalpages/views/default/admin/appearance/expages.php
@@ -0,0 +1,10 @@
+<?php
+/**
+ * Admin section for editing external pages
+ */
+
+$type = get_input('type', 'about');
+
+echo elgg_view('expages/menu', array('type' => $type));
+
+echo elgg_view_form('expages/edit', array('class' => 'elgg-form-settings'), array('type' => $type));
diff --git a/mod/externalpages/views/default/expages/menu.php b/mod/externalpages/views/default/expages/menu.php
new file mode 100644
index 000000000..831be9125
--- /dev/null
+++ b/mod/externalpages/views/default/expages/menu.php
@@ -0,0 +1,23 @@
+<?php
+/**
+ * External pages menu
+ *
+ * @uses $vars['type']
+ */
+
+$type = $vars['type'];
+
+//set the url
+$url = $vars['url'] . "admin/site/expages?type=";
+
+$pages = array('about', 'terms', 'privacy');
+$tabs = array();
+foreach ($pages as $page) {
+ $tabs[] = array(
+ 'title' => elgg_echo("expages:$page"),
+ 'url' => "admin/appearance/expages?type=$page",
+ 'selected' => $page == $type,
+ );
+}
+
+echo elgg_view('navigation/tabs', array('tabs' => $tabs, 'class' => 'elgg-form-settings'));
diff --git a/mod/externalpages/views/default/expages/wrapper.php b/mod/externalpages/views/default/expages/wrapper.php
new file mode 100644
index 000000000..c579da1ba
--- /dev/null
+++ b/mod/externalpages/views/default/expages/wrapper.php
@@ -0,0 +1,16 @@
+<?php
+/**
+ * Wrapper for site pages content area
+ *
+ * @uses $vars['content']
+ */
+
+echo $vars['content'];
+
+echo '<div class="mtm">';
+echo elgg_view('output/url', array(
+ 'text' => elgg_echo('back'),
+ 'href' => $_SERVER['HTTP_REFERER'],
+ 'class' => 'float-alt'
+));
+echo '</div>';
diff --git a/mod/externalpages/views/default/forms/expages/edit.php b/mod/externalpages/views/default/forms/expages/edit.php
new file mode 100644
index 000000000..a15f2a7aa
--- /dev/null
+++ b/mod/externalpages/views/default/forms/expages/edit.php
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Edit form body for external pages
+ *
+ * @uses $vars['type']
+ *
+ */
+
+$type = $vars['type'];
+
+//grab the required entity
+$page_contents = elgg_get_entities(array(
+ 'type' => 'object',
+ 'subtype' => $type,
+ 'limit' => 1,
+));
+
+if ($page_contents) {
+ $description = $page_contents[0]->description;
+ $guid = $page_contents[0]->guid;
+} else {
+ $description = "";
+ $guid = 0;
+}
+
+// set the required form variables
+$input_area = elgg_view('input/longtext', array(
+ 'name' => 'expagescontent',
+ 'value' => $description,
+));
+$submit_input = elgg_view('input/submit', array(
+ 'name' => 'submit',
+ 'value' => elgg_echo('save'),
+));
+$hidden_type = elgg_view('input/hidden', array(
+ 'name' => 'content_type',
+ 'value' => $type,
+));
+$hidden_guid = elgg_view('input/hidden', array(
+ 'name' => 'guid',
+ 'value' => $guid,
+));
+
+$external_page_title = elgg_echo("expages:$type");
+
+//construct the form
+echo <<<EOT
+<div class="mtm">
+ <label>$external_page_title</label>
+ $input_area
+</div>
+<div class="elgg-foot">
+$hidden_guid
+$hidden_type
+$submit_input
+</div>
+EOT;
+