edit.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Edit the images in a batch
  4. *
  5. * @author Cash Costello
  6. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
  7. */
  8. $guids = get_input('guid');
  9. $titles = get_input('title');
  10. $captions = get_input('caption');
  11. $tags = get_input('tags');
  12. $not_updated = array();
  13. foreach ($guids as $key => $guid) {
  14. $image = get_entity($guid);
  15. if ($image->canEdit()) {
  16. // set title appropriately
  17. if ($titles[$key]) {
  18. $image->title = $titles[$key];
  19. } else {
  20. $title = substr($image->originalfilename, 0, strrpos($image->originalfilename, '.'));
  21. // remove any possible bad characters from the title
  22. $image->title = preg_replace('/\W/', '', $title);
  23. }
  24. // set description appropriately
  25. $image->description = $captions[$key];
  26. $image->tags = string_to_tag_array($tags[$key]);
  27. if (!$image->save()) {
  28. array_push($not_updated, $image->getGUID());
  29. }
  30. }
  31. }
  32. if (count($not_updated) > 0) {
  33. register_error(elgg_echo("images:notedited"));
  34. } else {
  35. system_message(elgg_echo("images:edited"));
  36. }
  37. forward($image->getContainerEntity()->getURL());