BxFilesTemplate.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. $aParams['template_name'] = $sTemplateName;
  38. $aVars = $this->getUnit($aData, $aParams);
  39. $aFile = BxDolModule::getInstance($this->MODULE)->getContentFile($aData);
  40. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  41. $aVars['icon'] = $oStorage ? $oStorage->getFontIconNameByFileName($aFile['file_name']) : 'far file';
  42. if ($sTemplateName == 'unit_gallery.html')
  43. $aVars['bx_if:no_thumb']['content']['icon'] = $aVars['icon'];
  44. return $this->parseHtmlByName($sTemplateName, $aVars);
  45. }
  46. public function entryFilePreview ($aData)
  47. {
  48. $oModule = BxDolModule::getInstance($this->MODULE);
  49. $CNF = $oModule->_oConfig->CNF;
  50. $sNoPreview = MsgBox(_t('_bx_files_txt_preview_not_available'));
  51. if (!($aFile = $oModule->getContentFile($aData)))
  52. return $sNoPreview;
  53. if (!($oFileHandler = BxDolFileHandler::getObjectInstanceByFile($aFile['file_name'])))
  54. return $sNoPreview;
  55. if (!($oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE'])))
  56. return $sNoPreview;
  57. if (!($sFileUrl = $oStorage->getFileUrlById($aFile['id'])))
  58. return $sNoPreview;
  59. return $oFileHandler->display($sFileUrl, $aFile);
  60. }
  61. public function entryText ($aData, $sTemplateName = 'entry-text.html')
  62. {
  63. return $this->parseHtmlByName($sTemplateName, $this->getTmplVarsText($aData));
  64. }
  65. public function getTmplVarsText($aData)
  66. {
  67. $aVars = parent::getTmplVarsText($aData);
  68. $aVars = array_merge($aVars, array(
  69. 'entry_preview' => $this->entryFilePreview($aData),
  70. 'bx_if:show_content' => array(
  71. 'condition' => !empty($aVars['entry_title']) || !empty($aVars['entry_text']),
  72. 'content' => array(
  73. 'entry_title' => $aVars['entry_title'],
  74. 'entry_text' => $aVars['entry_text']
  75. )
  76. )
  77. ));
  78. return $aVars;
  79. }
  80. }
  81. /** @} */