BxBaseModTextTemplate.php 10 KB

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