BxFilesTemplate.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Files Files
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /*
  12. * Module representation.
  13. */
  14. class BxFilesTemplate extends BxBaseModTextTemplate
  15. {
  16. function __construct(&$oConfig, &$oDb)
  17. {
  18. $this->MODULE = 'bx_files';
  19. parent::__construct($oConfig, $oDb);
  20. }
  21. protected function getUnitThumbAndGallery ($aData)
  22. {
  23. $aFile = BxDolModule::getInstance($this->MODULE)->getContentFile($aData);
  24. if (!$aFile['is_image'])
  25. return array('', '');
  26. $sPhotoThumb = '';
  27. if ($oImagesTranscoder = BxDolTranscoderImage::getObjectInstance(BxDolModule::getInstance($this->MODULE)->_oConfig->CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']))
  28. $sPhotoThumb = $oImagesTranscoder->getFileUrl($aFile['id']);
  29. return array($sPhotoThumb, $sPhotoThumb);
  30. }
  31. function unit ($aData, $isCheckPrivateContent = true, $sTemplateName = 'unit.html', $aParams = array())
  32. {
  33. $sResult = $this->checkPrivacy ($aData, $isCheckPrivateContent, $this->getModule(), $sTemplateName);
  34. if($sResult)
  35. return $sResult;
  36. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  37. $aVars = $this->getUnit($aData, $aParams);
  38. $aFile = BxDolModule::getInstance($this->MODULE)->getContentFile($aData);
  39. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  40. $aVars['icon'] = $oStorage ? $oStorage->getFontIconNameByFileName($aFile['file_name']) : 'file-o';
  41. if ($sTemplateName == 'unit_gallery.html')
  42. $aVars['bx_if:no_thumb']['content']['icon'] = $aVars['icon'];
  43. return $this->parseHtmlByName($sTemplateName, $aVars);
  44. }
  45. function entryFilePreview ($aData)
  46. {
  47. $oModule = BxDolModule::getInstance($this->MODULE);
  48. $CNF = $oModule->_oConfig->CNF;
  49. $sNoPreview = MsgBox(_t('_bx_files_txt_preview_not_available'));
  50. if (!($aFile = $oModule->getContentFile($aData)))
  51. return $sNoPreview;
  52. if (!($oFileHandler = BxDolFileHandler::getObjectInstanceByFile($aFile['file_name'])))
  53. return $sNoPreview;
  54. if (!($oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE'])))
  55. return $sNoPreview;
  56. if (!($sFileUrl = $oStorage->getFileUrlById($aFile['id'])))
  57. return $sNoPreview;
  58. return $oFileHandler->display($sFileUrl, $aFile);
  59. }
  60. }
  61. /** @} */