aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCash Costello <cash.costello@gmail.com>2009-03-28 14:10:18 +0000
committerCash Costello <cash.costello@gmail.com>2009-03-28 14:10:18 +0000
commit871395b74470a70e37aeb684b820e289b0930cba (patch)
tree5761fdc33e08015fc9f56423f00ffbd73c6ecf84
parentd66faaf360f2f629fa96dd5e04ff0c6e38eb8213 (diff)
downloadelgg-871395b74470a70e37aeb684b820e289b0930cba.tar.gz
elgg-871395b74470a70e37aeb684b820e289b0930cba.tar.bz2
fixed bug with access levels and improved image and album editing
-rw-r--r--actions/edit.php121
-rw-r--r--views/default/tidypics/forms/edit.php82
2 files changed, 91 insertions, 112 deletions
diff --git a/actions/edit.php b/actions/edit.php
index 78b1f1653..a5d84bc18 100644
--- a/actions/edit.php
+++ b/actions/edit.php
@@ -1,7 +1,7 @@
<?php
/**
- * Tidypics edit album action
+ * Tidypics edit album/image action
*
*/
@@ -9,77 +9,68 @@
if (!isloggedin()) forward();
// Get input data
- $guid = (int) get_input('albumpost');
- $title = get_input('albumtitle');
- $body = get_input('albumbody');
- $access = get_input('access_id');
- $tags = get_input('albumtags');
- $back_url = 'mod/tidypics/edit.php?file_guid=' . $guid;
-
- // Make sure we actually have permission to edit
- $album = get_entity($guid);
- if ($album->canEdit())
- {
+ $guid = (int) get_input('guid'); // guid of image or album
+ $title = get_input('title');
+ $body = get_input('descript');
+ $access = get_input('access_id');
+ $tags = get_input('tags');
+ $subtype = get_input('subtype');
- // Cache to the session
- $_SESSION['albumtitle'] = $title;
- $_SESSION['albumbody'] = $body;
- $_SESSION['albumtags'] = $tags;
-
- // Convert string of tags into a preformatted array
- $tagarray = string_to_tag_array($tags);
-
- // Get owning user
- $owner = get_entity($album->getOwner());
-
- // edit access only if access is different from current
- if ($album->access_id != $access)
- {
- $album->access_id = $access;
+ $container_guid = get_input('container_guid');
+ error_log('container_guid is ' . $container_guid);
+
+ // Make sure we actually have permission to edit
+ $entity = get_entity($guid);
+ if (!$entity->canEdit()) {
+ forward();
+ }
+
+ // Get owning user/group
+ error_log("owning user is " . $entity->getOwner());
+ $owner = get_entity($entity->getOwner());
+
+ // change access only if access is different from current
+ if ($subtype == 'album' && $entity->access_id != $access) {
+ $entity->access_id = $access;
- //get images from album and update access on image entities
- $images = get_entities("object","image", $guid, '', 999, '', false);
- foreach ($images as $im) {
- $im->access_id = $access;
- $im->save();
- //new core updates all metadata access as well!
- }
+ //get images from album and update access on image entities
+ $images = get_entities("object","image", $guid, '', 999, '', false);
+ foreach ($images as $im) {
+ $im->access_id = $access;
+ $im->save();
}
+ }
- // Set its title and description appropriately
- $album->title = $title;
- $album->description = $body;
+ // Set its title and description appropriately
+ $entity->title = $title;
+ $entity->description = $body;
- // Before we can set metadata, we need to save the image
- if (!$album->save()) {
- register_error(elgg_echo("album:error"));
- $album->delete();
- forward(get_input('forward_url', $_SERVER['HTTP_REFERER'])); //failed, so forward to previous page
- }
+ // Before we can set metadata, we need to save the entity
+ if (!$entity->save()) {
+ register_error(elgg_echo("album:error"));
+ $entity->delete();
+ forward($_SERVER['HTTP_REFERER']); //failed, so forward to previous page
+ }
- // Now let's add tags. We can pass an array directly to the object property! Easy.
- $album->clearMetadata('tags');
- if (is_array($tagarray)) {
- $album->tags = $tagarray;
- }
-
- //if cover meta is sent from image save as metadata
- if (get_input('cover') == elgg_echo('album:cover:yes')) {
- $container = get_entity($album->container_guid);
- $container->cover = $album->guid;
- }
-
- // Success message
+ // Now let's add tags
+ $tagarray = string_to_tag_array($tags);
+ $entity->clearMetadata('tags');
+ if (is_array($tagarray)) {
+ $entity->tags = $tagarray;
+ }
+
+ //if cover meta is sent from image save as metadata
+ if ($subtype == 'image' && get_input('cover') == elgg_echo('album:cover:yes')) {
+ $album = get_entity($container_guid);
+ $album->cover = $entity->guid;
+ }
+
+ // Success message
+ if ($subtype == 'album')
system_message(elgg_echo("album:edited"));
-
- // Remove the image cache
- unset($_SESSION['albumtitle']);
- unset($_SESSION['albumbody']);
- unset($_SESSION['albumtags']);
-
- // Forward to the main blog page
- forward($album->getURL());
+ else
+ system_message(elgg_echo('images:edited'));
- }
+ forward($entity->getURL());
?> \ No newline at end of file
diff --git a/views/default/tidypics/forms/edit.php b/views/default/tidypics/forms/edit.php
index d59d029cc..0ed8cffab 100644
--- a/views/default/tidypics/forms/edit.php
+++ b/views/default/tidypics/forms/edit.php
@@ -1,26 +1,24 @@
<?php
/**
- * Tidypics images edit/add page
+ * Tidypics images edit/add form
* This form is used to:
* - create albums
* - edit albums
* - edit images
*/
-
+
//set stuff if we are editing existing album or image
if (isset($vars['entity'])) {
- $title = sprintf(elgg_echo("album:edit"),$object->title);
$action = "tidypics/edit";
$title = $vars['entity']->title;
$body = $vars['entity']->description;
$tags = $vars['entity']->tags;
$access_id = $vars['entity']->access_id;
$subtype = $vars['subtype'];
-
+
// if nothing is sent, create new, but only new albums are sent here
// new images are sent to upload.php
} else {
- $title = elgg_echo("album:add");
$action = "tidypics/addalbum";
$tags = "";
$title = "";
@@ -29,87 +27,77 @@
$access_id = ACCESS_DEFAULT;
else
$access_id = 0;
+ $subtype = 'album';
}
-
- // in case we have some cached details
- if (isset($vars['albumtitle'])) {
- $title = $vars['albumtitle'];
- $body = $vars['albumbody'];
- $tags = $vars['albumtags'];
- }
-
- $container_guid = get_input('container_guid');
- if (!$container_guid) $container_guid = page_owner();
+
+ // group or individual
+ $container_guid = page_owner();
?>
<div class="contentWrapper">
<form action="<?php echo $vars['url']; ?>action/<?php echo $action; ?>" method="post">
<p>
<label><?php echo elgg_echo('album:title'); ?></label>
- <?php echo elgg_view("input/text", array("internalname" => "albumtitle", "value" => $title,)); ?>
+ <?php echo elgg_view("input/text", array("internalname" => "title", "value" => $title,)); ?>
</p>
-<?php
- if ($vars['subtype'] == 'album' || $action == "tidypics/addalbum") {
+<?php
+ if ($subtype == 'album') {
?>
<p>
<label><?php echo elgg_echo('album:desc'); ?></label>
- <?php echo elgg_view("input/text",array("internalname" => "albumbody","value" => $body,)); ?>
+ <?php echo elgg_view("input/text",array("internalname" => "descript","value" => $body,)); ?>
</p>
<?php
} else {
?>
<p>
<label><?php echo elgg_echo('caption'); ?></label>
- <?php echo elgg_view("input/text",array("internalname" => "albumbody","value" => $body,)); ?>
+ <?php echo elgg_view("input/text",array("internalname" => "descript","value" => $body,)); ?>
</p>
<?php
- } //End album/image selection
+ }
?>
<p>
<label><?php echo elgg_echo("tags"); ?></label>
- <?php echo elgg_view("input/tags", array( "internalname" => "albumtags","value" => $tags,)); ?>
+ <?php echo elgg_view("input/tags", array( "internalname" => "tags","value" => $tags,)); ?>
</p>
- <?php
-
- if($vars['subtype'] == 'image')
- {
- //if this is an image --
- //ALBUM COVER: ask to set image to album cover ::
- //ACCESS: only existing images come here :: so acess should already be initially set by album
-
+<?php
+ if ($subtype == 'image') {
+ // should this album be the cover for the album
+
+ // try to determine if it is already the cover - the pass of this variable doesn't work - leave for next version
$guid = $vars['entity']->guid;
$container_guid = $vars['entity']->container_guid;
$cover_guid = get_entity($container_guid)->cover;
-
if($cover_guid == $vars['entity']->guid)
$cover = 'yes';
- ?>
+?>
<p>
<label><?php echo elgg_echo("album:cover"); ?></label>
<?php echo elgg_view("input/cover_checkbox", array( "internalname" => "cover", "value" => $cover, 'options' => array(elgg_echo('album:cover:yes')))); ?>
</p>
- <?php
- }
- else{
- //this is a new or existing album, both of which access is editable
- ?>
+<?php
+ } else {
+ // album so display access control
+?>
<p>
- <label><?php echo sprintf(elgg_echo('access'), "$subtype"); ?></label>
- <?php echo elgg_view('input/access', array('internalname' => 'access_id','value' => $access_id)); ?>
- </p>
-
- <?php
+ <label><?php echo elgg_echo('access'); ?></label>
+ <?php echo elgg_view('input/access', array('internalname' => 'access_id','value' => $access_id)); ?>
+ </p>
+
+<?php
}
if (isset($vars['entity'])) {
- ?>
- <input type="hidden" name="albumpost" value="<?php echo $vars['entity']->getGUID(); ?>" />
- <?php
+?>
+ <input type="hidden" name="guid" value="<?php echo $vars['entity']->getGUID(); ?>" />
+<?php
}
- ?>
- <input type="hidden" name="container_guid" value="<?php echo $container_guid; ?>" />
+?>
+ <input type="hidden" name="container_guid" value="<?php echo $container_guid; ?>" />
+ <input type="hidden" name="subtype" value="<?php echo $subtype; ?>" />
<p><input type="submit" name="submit" value="<?php echo elgg_echo('save'); ?>" /></p>
</form>
</div> \ No newline at end of file