BxBaseModTextTemplate.php 10 KB

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