BxAlbumsFormEntry.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Albums Albums
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Create/Edit entry form
  13. */
  14. class BxAlbumsFormEntry extends BxBaseModTextFormEntry
  15. {
  16. public function __construct($aInfo, $oTemplate = false)
  17. {
  18. $this->MODULE = 'bx_albums';
  19. parent::__construct($aInfo, $oTemplate);
  20. }
  21. protected function _associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId, $sPictureField = '')
  22. {
  23. parent::_associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId, $sPictureField);
  24. $CNF = &$this->_oModule->_oConfig->CNF;
  25. $sData = '';
  26. $sExif = '';
  27. $aExif = false;
  28. $aFile = $oStorage->getFile($iFileId);
  29. if (0 === strncmp('image/', $aFile['mime_type'], 6)) {
  30. $oImageReize = BxDolImageResize::getInstance();
  31. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_BIG']);
  32. $a = $oImageReize->getImageSize($oTranscoder->getFileUrl($iFileId));
  33. $sData = isset($a['w']) && isset($a['h']) ? $a['w'] . 'x' . $a['h'] : '';
  34. if ($aExif = $oImageReize->getExifInfo($oStorage->getFileUrlById($iFileId))) {
  35. $a = array('Make', 'Model', 'FocalLength', 'ShutterSpeedValue', 'ExposureTime', 'ISOSpeedRatings', 'Orientation', 'Artist', 'Copyright', 'Flash', 'WhiteBalance', 'DateTimeOriginal', 'DateTimeDigitized', 'ExifVersion', 'COMPUTED', 'GPSLatitudeRef', 'GPSLatitude', 'GPSLongitudeRef', 'GPSLongitude', 'GPSAltitudeRef', 'GPSAltitude', 'GPSTimeStamp', 'GPSImgDirectionRef', 'GPSImgDirection', 'GPSDateStamp');
  36. $aExifFiltered = array();
  37. foreach ($a as $sIndex)
  38. if (isset($aExif[$sIndex]))
  39. $aExifFiltered[$sIndex] = $aExif[$sIndex];
  40. $sExif = serialize($aExifFiltered);
  41. }
  42. }
  43. if (false === $this->_oModule->_oDb->associateFileWithContent ($iContentId, $iFileId, $this->getCleanValue('title-' . $iFileId), $sData, $sExif))
  44. return;
  45. $aMediaInfo = $this->_oModule->_oDb->getMediaInfoSimpleByFileId($iFileId);
  46. if ($aMediaInfo && !empty($CNF['OBJECT_METATAGS_MEDIA'])) {
  47. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS_MEDIA']);
  48. if ($oMetatags->keywordsIsEnabled())
  49. $oMetatags->keywordsAdd($aMediaInfo['id'], $aMediaInfo['title']);
  50. }
  51. if ($aMediaInfo && isset($aExif['Make']) && !empty($CNF['OBJECT_METATAGS_MEDIA_CAMERA'])) {
  52. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS_MEDIA_CAMERA']);
  53. if ($oMetatags->keywordsIsEnabled())
  54. $oMetatags->keywordsAddOne($aMediaInfo['id'], $oMetatags->keywordsCameraModel($aExif));
  55. }
  56. }
  57. function _deleteFile ($iFileId, $sStorage = '')
  58. {
  59. if (!($bRet = parent::_deleteFile ($iFileId)))
  60. return false;
  61. $this->_oModule->serviceDeleteFileAssociations ($iFileId);
  62. return true;
  63. }
  64. function delete ($iContentId, $aContentInfo = array())
  65. {
  66. if (!($bRet = parent::delete ($iContentId, $aContentInfo)))
  67. return $bRet;
  68. if (!($aMediaList = $this->_oModule->_oDb->getMediaListByContentId($iContentId)))
  69. return $bRet;
  70. foreach ($aMediaList as $aMediaInfo)
  71. $this->_oModule->serviceDeleteFileAssociations($aMediaInfo['file_id']);
  72. return $bRet;
  73. }
  74. }
  75. /** @} */