BxBaseModTextTemplate.php 11 KB

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