/klutz/savecomic.php

https://github.com/ewandor/horde · PHP · 66 lines · 45 code · 6 blank · 15 comment · 7 complexity · 25f3ed277b49dacef087714c2e8c5124 MD5 · raw file

  1. <?php
  2. /**
  3. * Script for saving a comic to an image gallery. UI template stolen from
  4. * Imp's saveimage functionality.
  5. *
  6. * Copyright 2005-2012 Horde LLC (http://www.horde.org/)
  7. *
  8. * See the enclosed file COPYING for license information (GPL). If you
  9. * did not receive this file, see http://www.horde.org/licenses/gpl.
  10. *
  11. * @author Michael Slusarz <slusarz@horde.org>
  12. * @author Michael Rubinsky <mrubinsk@horde.org>
  13. */
  14. require_once dirname(__FILE__) . '/lib/Application.php';
  15. Horde_Registry::appInit('klutz');
  16. $index = Horde_Util::getFormData('index');
  17. $date = Horde_Util::getFormData('date');
  18. $actionID = Horde_Util::getFormData('actionID');
  19. $tags = Horde_Util::getFormData('tags');
  20. /* We'll need the comic object to build the image name */
  21. $comic = $klutz->comicObject($index);
  22. switch ($actionID) {
  23. case 'save_comic':
  24. /* Try to retrieve the image directly from storage first*/
  25. $image = $klutz_driver->retrieveImage($index, $date);
  26. if (is_string($image) && substr($image, 0, 4) == 'http') {
  27. $comic = $klutz->comicObject($index);
  28. $image = $comic->fetchImage($date);
  29. }
  30. if (!is_a($image, 'Klutz_Image')) {
  31. PEAR::raiseError(_("There was an error retrieving the comic."));
  32. } else {
  33. $desc = Horde_Util::getFormData('desc', '');
  34. $image_data = array(
  35. 'filename' => $comic->name . '-' . strftime('%m%d%Y', $date) . '.' . str_replace('image/', '', $image->type), // Suggestions for better name?
  36. 'description' => $desc,
  37. 'data' => $image->data,
  38. 'type' => $image->type,
  39. 'tags' => explode(',', $tags)
  40. );
  41. $gallery = Horde_Util::getFormData('gallery');
  42. $res = $registry->call('images/saveImage',
  43. array(null, $gallery, $image_data));
  44. if (is_a($res, 'PEAR_Error')) {
  45. $notification->push($res, 'horde.error');
  46. break;
  47. }
  48. Horde_Util::closeWindowJS();
  49. }
  50. exit;
  51. }
  52. /* Build the list of galleries. */
  53. $id = $prefs->getValue('comicgallery');
  54. $gallerylist = $registry->call('images/selectGalleries',
  55. array(null, PERMS_EDIT, null,
  56. true, 0, 0, $id));
  57. $title = _("Save Image");
  58. require $registry->get('templates', 'horde') . '/common-header.inc';
  59. require KLUTZ_TEMPLATES . '/savecomic.html.php';
  60. require $registry->get('templates', 'horde') . '/common-footer.inc';