From 4e2a58e02ae4fe55ebc801a816c6ddb304df4b18 Mon Sep 17 00:00:00 2001 From: brettp Date: Tue, 9 Mar 2010 00:52:52 +0000 Subject: Brought sitepages up to standards. Added basic static keyword/view substitution support. git-svn-id: http://code.elgg.org/elgg/trunk@5312 36083f99-b078-4883-b0ff-0f9b5a30f544 --- mod/sitepages/actions/add.php | 93 +++++++++++++++++--------------------- mod/sitepages/actions/addfront.php | 66 +++++++++++---------------- mod/sitepages/actions/addmeta.php | 59 ++++++++++-------------- 3 files changed, 91 insertions(+), 127 deletions(-) (limited to 'mod/sitepages/actions') diff --git a/mod/sitepages/actions/add.php b/mod/sitepages/actions/add.php index 3b7f4eb2d..bc38d8067 100644 --- a/mod/sitepages/actions/add.php +++ b/mod/sitepages/actions/add.php @@ -1,64 +1,53 @@ + * @copyright Curverider Ltd 2008-2010 + * @link http://elgg.com/ + * */ // Make sure we're logged as admin admin_gatekeeper(); // Get input data -$contents = get_input('sitepagescontent', '', false); -$type = get_input('content_type'); -$tags = get_input('sitepagestags'); -$previous_guid = get_input('expage_guid'); +$content = get_input('sitepages_content', '', FALSE); +$page_type = get_input('page_type'); +$tags = get_input('sitepages_tags'); +$tag_array = string_to_tag_array($tags); -// Cache to the session -$_SESSION['sitepages_content'] = $contents; -$_SESSION['sitepagestype'] = $type; -$_SESSION['sitepagestags'] = $tags; - -// Convert string of tags into a preformatted array -$tagarray = string_to_tag_array($tags); - -// Make sure the content exists -if (empty($contents)) { - register_error(elgg_echo("sitepages:blank")); - forward("mod/sitepages/add.php"); - -// Otherwise, save the new external page +// Cache to the session for sticky forms +// @todo make these work. +$_SESSION['sitepages_content'] = $content; +$_SESSION['sitepages_type'] = $type; +$_SESSION['sitepages_tags'] = $tags; + +if (!$sitepage = sitepages_get_sitepage_object($page_type)) { + $sitepage = sitepages_create_sitepage_object($page_type); +} + +if (empty($content)) { + register_error(elgg_echo('sitepages:blank')); } else { - //remove the old external page - if(get_entity($previous_guid)){ - delete_entity($previous_guid); - } - - // Initialise a new ElggObject - $sitepages = new ElggObject(); - // Tell the system what type of external page it is - $sitepages->subtype = $type; - // Set its owner to the current user - $sitepages->owner_guid = $_SESSION['user']->getGUID(); - // For now, set its access to public - $sitepages->access_id = 2; - // Set its title and description appropriately - $sitepages->title = $type; - $sitepages->description = $contents; - // Before we can set metadata, save - if (!$sitepages->save()) { - register_error(elgg_echo("sitepages:error")); - forward("mod/sitepages/add.php"); - } - // Now let's add tags. We can pass an array directly to the object property! Easy. - if (is_array($tagarray)) { - $sitepages->tags = $tagarray; + $sitepage->title = $type; + $sitepage->description = $content; + $sitepage->tags = $tag_array; + + if (!$sitepage->save()) { + register_error(elgg_echo('sitepages:error')); + } else { + system_message(elgg_echo('sitepages:posted')); + // @todo this needs to be accurate for create or update. + add_to_river('river/sitepages/create', 'create', $_SESSION['user']->guid, $sitepages->guid); } - // Success message - system_message(elgg_echo("sitepages:posted")); - // add to river - add_to_river('river/sitepages/create','create',$_SESSION['user']->guid,$sitepages->guid); - // Remove the cache - unset($_SESSION['sitepages_content']); unset($_SESSION['sitepagestitle']); unset($_SESSION['sitepagestags']); - - // Forward back to the page - forward("pg/sitepages/index.php?type={$type}"); + + // @todo Good intensions... + unset($_SESSION['sitepages_content']); + unset($_SESSION['sitepagestitle']); + unset($_SESSION['sitepagestags']); } + +forward($_SERVER['HTTP_REFERER']); \ No newline at end of file diff --git a/mod/sitepages/actions/addfront.php b/mod/sitepages/actions/addfront.php index 5a86189db..6b8782da7 100644 --- a/mod/sitepages/actions/addfront.php +++ b/mod/sitepages/actions/addfront.php @@ -1,51 +1,39 @@ + * @copyright Curverider Ltd 2008-2010 + * @link http://elgg.com/ + * */ -// Make sure we're logged as admin admin_gatekeeper(); -// Get input data -$frontContents = get_input('frontContents'); -$css = get_input('css'); -$previous_guid = get_input('front_guid'); - -//remove the old front page -if(get_entity($previous_guid)){ - delete_entity($previous_guid); +$content = get_input('sitepages_content', '', FALSE); +$css = get_input('css', '', FALSE); +$loggedin_user_guid = get_loggedin_userid(); + +// Cache to the session for sticky forms +// @todo does nothing yet. +$_SESSION['sitepages:content'] = $content; +$_SESSION['sitepages:css'] = $css; + +if (!$sitepage = sitepages_get_sitepage_object('front')) { + $sitepage = sitepages_create_sitepage_object('front'); } -//var_export($pageshell);exit; +$sitepage->title = $css; +$sitepage->description = $content; -// Cache to the session -$_SESSION['pageshell'] = $pageshell; -$_SESSION['css'] = $css; - -// Initialise a new ElggObject -$frontpage = new ElggObject(); -// Tell the system what type of external page it is -$frontpage->subtype = "frontpage"; -// Set its owner to the current user -$frontpage->owner_guid = $_SESSION['user']->getGUID(); -// Set its access to public -$frontpage->access_id = 2; -// Set its title and description appropriately -$frontpage->title = $css; -$frontpage->description = $frontContents; - -// Before we can set metadata, save -if (!$frontpage->save()) { +if ($sitepage->save()) { + system_message(elgg_echo("sitepages:posted")); + unset($_SESSION['sitepages:content']); + unset($_SESSION['sitepages:css']); +} else { register_error(elgg_echo("sitepages:error")); - forward("pg/sitepages/index.php?type=front"); } -// Success message -system_message(elgg_echo("sitepages:posted")); - -// Remove the cache -unset($_SESSION['css']); unset($_SESSION['pageshell']); - - -// Forward back to the page -forward("pg/sitepages/index.php?type=front"); +forward($_SERVER['HTTP_REFERER']); \ No newline at end of file diff --git a/mod/sitepages/actions/addmeta.php b/mod/sitepages/actions/addmeta.php index 432152ef1..e9f40cdb4 100644 --- a/mod/sitepages/actions/addmeta.php +++ b/mod/sitepages/actions/addmeta.php @@ -1,49 +1,36 @@ + * @copyright Curverider Ltd 2008-2010 + * @link http://elgg.com/ + * */ -// Make sure we're logged as admin admin_gatekeeper(); -// Get input data -$description = get_input('description', '', false); -$metatags = get_input('metatags', '', false); -$previous_guid = get_input('seo_guid'); - -//remove the old front page -if(get_entity($previous_guid)){ - delete_entity($previous_guid); -} +$description = get_input('description', '', FALSE); +$metatags = get_input('metatags', '', FALSE); // Cache to the session $_SESSION['description'] = $description; $_SESSION['metatags'] = $metatags; - -// Initialise a new ElggObject -$seo = new ElggObject(); -// Tell the system what type of external page it is -$seo->subtype = "sitemeta"; -// Set its owner to the current user -$seo->owner_guid = $_SESSION['user']->getGUID(); -// Set its access to public -$seo->access_id = 2; -// Set its title and description appropriately -$seo->title = $metatags; -$seo->description = $description; - -// Before we can set metadata, save -if (!$seo->save()) { - register_error(elgg_echo("sitepages:error")); - forward("pg/sitepages/index.php?type=seo"); + +if (!$sitepage = sitepages_get_sitepage_object('front')) { + $sitepage = sitepages_create_sitepage_object('front'); } -// Success message -system_message(elgg_echo("sitepages:seocreated")); +$sitepage->title = $metatags; +$sitepage->description = $description; + +if ($sitepage->save()) { + system_message(elgg_echo("sitepages:seocreated")); + unset($_SESSION['description']); unset($_SESSION['metatags']); +} else { + register_error(elgg_echo("sitepages:error")); +} -// Remove the cache -unset($_SESSION['description']); unset($_SESSION['metatags']); - - -// Forward back to the page -forward("pg/sitepages/index.php?type=seo"); +forward($_SERVER['HTTP_REFERER']); \ No newline at end of file -- cgit v1.2.3