BxBaseModTextTemplate.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 BaseText Base classes for text modules
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxBaseModGeneralTemplate');
  12. /**
  13. * Module representation.
  14. */
  15. class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
  16. {
  17. function __construct(&$oConfig, &$oDb)
  18. {
  19. parent::__construct($oConfig, $oDb);
  20. }
  21. function unit ($aData, $isCheckPrivateContent = true, $sTemplateName = 'unit.html')
  22. {
  23. $oModule = BxDolModule::getInstance($this->MODULE);
  24. $CNF = &$oModule->_oConfig->CNF;
  25. if ($s = $this->checkPrivacy ($aData, $isCheckPrivateContent, $oModule))
  26. return $s;
  27. // get thumb url
  28. $sPhotoThumb = '';
  29. if ($aData[$CNF['FIELD_THUMB']]) {
  30. bx_import('BxDolTranscoderImage');
  31. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  32. if ($oImagesTranscoder)
  33. $sPhotoThumb = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  34. }
  35. // get entry url
  36. bx_import('BxDolPermalinks');
  37. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]);
  38. bx_import('BxDolProfile');
  39. $oProfile = BxDolProfile::getInstance($aData[$CNF['FIELD_AUTHOR']]);
  40. if (!$oProfile) {
  41. bx_import('BxDolProfileUndefined');
  42. $oProfile = BxDolProfileUndefined::getInstance();
  43. }
  44. // get summary
  45. $sLinkMore = ' <a title="' . bx_html_attribute(_t('_sys_read_more', $aData[$CNF['FIELD_TITLE']])) . '" href="' . $sUrl . '"><i class="sys-icon ellipsis-h"></i></a>';
  46. $sSummary = strmaxtextlen($aData[$CNF['FIELD_TEXT']], (int)getParam($CNF['PARAM_CHARS_SUMMARY']), $sLinkMore);
  47. $sSummaryPlain = BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($sSummary), (int)getParam($CNF['PARAM_CHARS_SUMMARY_PLAIN']));
  48. // generate html
  49. $aVars = array (
  50. 'id' => $aData[$CNF['FIELD_ID']],
  51. 'content_url' => $sUrl,
  52. 'title' => bx_process_output($aData[$CNF['FIELD_TITLE']]),
  53. 'summary' => $sSummary,
  54. 'author' => $oProfile->getDisplayName(),
  55. 'author_url' => $oProfile->getUrl(),
  56. 'entry_posting_date' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE),
  57. 'module_name' => _t($CNF['T']['txt_sample_single']),
  58. 'ts' => $aData[$CNF['FIELD_ADDED']],
  59. 'bx_if:thumb' => array (
  60. 'condition' => $sPhotoThumb,
  61. 'content' => array (
  62. 'title' => bx_process_output($aData[$CNF['FIELD_TITLE']]),
  63. 'summary_attr' => bx_html_attribute($sSummaryPlain),
  64. 'content_url' => $sUrl,
  65. 'thumb_url' => $sPhotoThumb ? $sPhotoThumb : '',
  66. ),
  67. ),
  68. 'bx_if:no_thumb' => array (
  69. 'condition' => !$sPhotoThumb,
  70. 'content' => array (
  71. 'content_url' => $sUrl,
  72. 'summary_plain' => $sSummaryPlain,
  73. ),
  74. ),
  75. );
  76. return $this->parseHtmlByName($sTemplateName, $aVars);
  77. }
  78. function entryText ($aData, $sTemplateName = 'entry-text.html')
  79. {
  80. $oModule = BxDolModule::getInstance($this->MODULE);
  81. $CNF = &$oModule->_oConfig->CNF;
  82. $aVars = $aData;
  83. $aVars['entry_title'] = isset($aData[$CNF['FIELD_TITLE']]) ? $aData[$CNF['FIELD_TITLE']] : '';
  84. $aVars['entry_text'] = $aData[$CNF['FIELD_TEXT']];
  85. if (!empty($CNF['OBJECT_METATAGS'])) {
  86. bx_import('BxDolMetatags');
  87. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  88. // keywords
  89. $aFields = $oMetatags->keywordsFields($aData, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_VIEW']);
  90. foreach ($aFields as $sField)
  91. $aVars[$sField] = $oMetatags->keywordsParse($aData[$CNF['FIELD_ID']], $aVars[$sField]);
  92. // location
  93. $aVars['location'] = $oMetatags->locationsString($aData[$CNF['FIELD_ID']]);
  94. }
  95. return $this->parseHtmlByName($sTemplateName, $aVars);
  96. }
  97. function entryAuthor ($aData, $sTemplateName = 'author.html')
  98. {
  99. $oModule = BxDolModule::getInstance($this->MODULE);
  100. $CNF = &$oModule->_oConfig->CNF;
  101. $oProfile = BxDolProfile::getInstance($aData[$CNF['FIELD_AUTHOR']]);
  102. if (!$oProfile) {
  103. bx_import('BxDolProfileUndefined');
  104. $oProfile = BxDolProfileUndefined::getInstance();
  105. }
  106. if (!$oProfile)
  107. return '';
  108. $aVars = array (
  109. 'author_url' => $oProfile->getUrl(),
  110. 'author_thumb_url' => $oProfile->getThumb(),
  111. 'author_title' => $oProfile->getDisplayName(),
  112. 'author_desc' => $this->getAuthorDesc($aData),
  113. );
  114. return $this->parseHtmlByName($sTemplateName, $aVars);
  115. }
  116. function getAuthorDesc ($aData)
  117. {
  118. $oModule = BxDolModule::getInstance($this->MODULE);
  119. return bx_time_js($aData[$oModule->_oConfig->CNF['FIELD_ADDED']], BX_FORMAT_DATE);
  120. }
  121. function entryAttachments ($aData)
  122. {
  123. $oModule = BxDolModule::getInstance($this->MODULE);
  124. $CNF = &$oModule->_oConfig->CNF;
  125. bx_import('BxTemplFunctions');
  126. bx_import('BxDolStorage');
  127. bx_import('BxDolTranscoderImage');
  128. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  129. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  130. $aTranscodersVideo = false;
  131. if ($CNF['OBJECT_VIDEOS_TRANSCODERS'])
  132. $aTranscodersVideo = array (
  133. 'poster' => BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']),
  134. 'mp4' => BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']),
  135. 'webm' => BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['webm']),
  136. );
  137. $aGhostFiles = $oStorage->getGhosts ($aData[$CNF['FIELD_AUTHOR']], $aData[$CNF['FIELD_ID']]);
  138. if (!$aGhostFiles)
  139. return false;
  140. foreach ($aGhostFiles as $k => $a) {
  141. $isImage = $oTranscoder && (0 == strncmp('image/', $a['mime_type'], 6)); // preview for images, transcoder object for preview must be defined
  142. $isVideo = $aTranscodersVideo && (0 == strncmp('video/', $a['mime_type'], 6)); // preview for videos, transcoder object for video must be defined
  143. $sUrlOriginal = $oStorage->getFileUrlById($a['id']);
  144. $sImgPopupId = 'bx-messages-atachment-popup-' . $a['id'];
  145. // images are displayed with preview and popup upon clicking
  146. $aGhostFiles[$k]['bx_if:image'] = array (
  147. 'condition' => $isImage,
  148. 'content' => array (
  149. 'url_original' => $sUrlOriginal,
  150. 'attr_file_name' => bx_html_attribute($a['file_name']),
  151. 'popup_id' => $sImgPopupId,
  152. 'url_preview' => $oTranscoder->getFileUrl($a['id']),
  153. 'popup' => BxTemplFunctions::getInstance()->transBox($sImgPopupId, '<img src="' . $sUrlOriginal . '" />', true, true),
  154. ),
  155. );
  156. // videos are displayed inline
  157. $aGhostFiles[$k]['bx_if:video'] = array (
  158. 'condition' => $isVideo,
  159. 'content' => array (
  160. 'video' => $aTranscodersVideo ? BxTemplFunctions::getInstance()->videoPlayer(
  161. $aTranscodersVideo['poster']->getFileUrl($a['id']),
  162. $aTranscodersVideo['mp4']->getFileUrl($a['id']),
  163. $aTranscodersVideo['webm']->getFileUrl($a['id']),
  164. false, ''
  165. ) : '',
  166. ),
  167. );
  168. // non-images are displayed as text links to original file
  169. $aGhostFiles[$k]['bx_if:not_image'] = array (
  170. 'condition' => !$isImage && !$isVideo,
  171. 'content' => array (
  172. 'url_original' => $sUrlOriginal,
  173. 'attr_file_name' => bx_html_attribute($a['file_name']),
  174. 'file_name' => bx_process_output($a['file_name']),
  175. ),
  176. );
  177. }
  178. $aVars = array(
  179. 'bx_repeat:attachments' => $aGhostFiles,
  180. );
  181. return $this->parseHtmlByName('attachments.html', $aVars);
  182. }
  183. protected function checkPrivacy ($aData, $isCheckPrivateContent, $oModule)
  184. {
  185. if ($isCheckPrivateContent && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $oModule->checkAllowedView($aData))) {
  186. $aVars = array (
  187. 'summary' => $sMsg,
  188. );
  189. return $this->parseHtmlByName('unit_private.html', $aVars);
  190. }
  191. return '';
  192. }
  193. }
  194. /** @} */