BxBaseModTextTemplate.php 10 KB

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