70c139fed11cd09060fbfbc1d5287117.resolve.spaces.resolver 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Gallery
  4. *
  5. * Copyright 2010-2012 by Shaun McCormick <shaun@modx.com>
  6. *
  7. * Gallery is free software; you can redistribute it and/or modify it under the
  8. * terms of the GNU General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option) any later
  10. * version.
  11. *
  12. * Gallery is distributed in the hope that it will be useful, but WITHOUT ANY
  13. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  14. * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * Gallery; if not, write to the Free Software Foundation, Inc., 59 Temple
  18. * Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. * @package gallery
  21. */
  22. /**
  23. * Resolve spaces in image filenames
  24. *
  25. * @package gallery
  26. * @subpackage build
  27. */
  28. if ($object->xpdo) {
  29. switch ($options[xPDOTransport::PACKAGE_ACTION]) {
  30. case xPDOTransport::ACTION_INSTALL:
  31. $modx =& $object->xpdo;
  32. $modelPath = $modx->getOption('gallery.core_path',null,$modx->getOption('core_path').'components/gallery/').'model/';
  33. $modx->addPackage('gallery',$modelPath);
  34. $filesPath = $modx->getOption('gallery.files_path',null,$modx->getOption('assets_path',null,MODX_ASSETS_PATH).'components/gallery/files/');
  35. $items = $modx->getCollection('galItem');
  36. foreach ($items as $item) {
  37. $filename = $item->get('filename');
  38. $filenameNoSpaces = str_replace(' ','',$filename);
  39. if (strcmp($filenameNoSpaces,$filename) !== 0) {
  40. $path = $filesPath;
  41. $newFile = $path . $filenameNoSpaces;
  42. $oldFile = $path . $filename;
  43. if (@copy($oldFile,$newFile)) {
  44. @unlink($oldFile);
  45. $item->set('filename',$filenameNoSpaces);
  46. $item->save();
  47. }
  48. }
  49. }
  50. break;
  51. case xPDOTransport::ACTION_UPGRADE:
  52. break;
  53. }
  54. }
  55. return true;