BxBaseModTextTemplate.php 11 KB

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