BxBaseModTextTemplate.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 DolphinModules
  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')
  22. {
  23. $oModule = BxDolModule::getInstance($this->MODULE);
  24. $CNF = &$oModule->_oConfig->CNF;
  25. if ($isCheckPrivateContent && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $oModule->checkAllowedView($aData))) {
  26. $aVars = array (
  27. 'summary' => $sMsg,
  28. );
  29. return $this->parseHtmlByName('unit_private.html', $aVars);
  30. }
  31. // get thumb url
  32. $sPhotoThumb = '';
  33. if ($aData[$CNF['FIELD_THUMB']]) {
  34. bx_import('BxDolImageTranscoder');
  35. $oImagesTranscoder = BxDolImageTranscoder::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  36. if ($oImagesTranscoder)
  37. $sPhotoThumb = $oImagesTranscoder->getImageUrl($aData[$CNF['FIELD_THUMB']]);
  38. }
  39. // get entry url
  40. bx_import('BxDolPermalinks');
  41. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]);
  42. bx_import('BxDolProfile');
  43. $oProfile = BxDolProfile::getInstance($aData[$CNF['FIELD_AUTHOR']]);
  44. if (!$oProfile) {
  45. bx_import('BxDolProfileUndefined');
  46. $oProfile = BxDolProfileUndefined::getInstance();
  47. }
  48. $sSummary = $aData[$CNF['FIELD_SUMMARY']];
  49. if (!$sSummary) {
  50. $iLimitChars = (int)getParam($CNF['PARAM_CHARS_SUMMARY']);
  51. $sSummary = trim(strip_tags($aData[$CNF['FIELD_TEXT']]));
  52. $sLinkMore = '';
  53. if (mb_strlen($sSummary) > $iLimitChars) {
  54. $sSummary = mb_substr($sSummary, 0, $iLimitChars);
  55. $sLinkMore = ' <a title="' . bx_html_attribute(_t('_sys_read_more', $aData[$CNF['FIELD_TITLE']])) . '" href="' . $sUrl . '"><i class="sys-icon ellipsis-horizontal"></i></a>';
  56. }
  57. $sSummary = htmlspecialchars_adv($sSummary) . $sLinkMore;
  58. }
  59. $sSummaryPlain = BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($sSummary), (int)getParam($CNF['PARAM_CHARS_SUMMARY_PLAIN']));
  60. // generate html
  61. $aVars = array (
  62. 'id' => $aData[$CNF['FIELD_ID']],
  63. 'content_url' => $sUrl,
  64. 'title' => bx_process_output($aData[$CNF['FIELD_TITLE']]),
  65. 'summary' => $sSummary,
  66. 'author' => $oProfile->getDisplayName(),
  67. 'author_url' => $oProfile->getUrl(),
  68. 'entry_posting_date' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE),
  69. 'bx_if:thumb' => array (
  70. 'condition' => $sPhotoThumb,
  71. 'content' => array (
  72. 'title' => bx_process_output($aData[$CNF['FIELD_TITLE']]),
  73. 'summary_attr' => bx_html_attribute($sSummaryPlain),
  74. 'content_url' => $sUrl,
  75. 'thumb_url' => $sPhotoThumb ? $sPhotoThumb : '',
  76. ),
  77. ),
  78. 'bx_if:no_thumb' => array (
  79. 'condition' => !$sPhotoThumb,
  80. 'content' => array (
  81. 'content_url' => $sUrl,
  82. 'summary_plain' => $sSummaryPlain,
  83. ),
  84. ),
  85. );
  86. return $this->parseHtmlByName($sTemplateName, $aVars);
  87. }
  88. function entryText ($aData, $sTemplateName = 'entry-text.html')
  89. {
  90. $oModule = BxDolModule::getInstance($this->MODULE);
  91. $CNF = &$oModule->_oConfig->CNF;
  92. $aVars = $aData;
  93. $aVars['entry_title'] = isset($aData[$CNF['FIELD_TITLE']]) ? $aData[$CNF['FIELD_TITLE']] : '';
  94. $aVars['entry_text'] = $aData[$CNF['FIELD_TEXT']];
  95. return $this->parseHtmlByName($sTemplateName, $aVars);
  96. }
  97. function entryAuthor ($aData, $sTemplateName = 'author.html')
  98. {
  99. $oModule = BxDolModule::getInstance($this->MODULE);
  100. $CNF = &$oModule->_oConfig->CNF;
  101. $oProfile = BxDolProfile::getInstance($aData[$CNF['FIELD_AUTHOR']]);
  102. if (!$oProfile) {
  103. bx_import('BxDolProfileUndefined');
  104. $oProfile = BxDolProfileUndefined::getInstance();
  105. }
  106. if (!$oProfile)
  107. return '';
  108. $aVars = array (
  109. 'author_url' => $oProfile->getUrl(),
  110. 'author_thumb_url' => $oProfile->getThumb(),
  111. 'author_title' => $oProfile->getDisplayName(),
  112. 'author_desc' => $this->getAuthorDesc($aData),
  113. );
  114. return $this->parseHtmlByName($sTemplateName, $aVars);
  115. }
  116. function getAuthorDesc ($aData)
  117. {
  118. $oModule = BxDolModule::getInstance($this->MODULE);
  119. return bx_time_js($aData[$oModule->_oConfig->CNF['FIELD_ADDED']], BX_FORMAT_DATE);
  120. }
  121. function entryAttachments ($aData)
  122. {
  123. $oModule = BxDolModule::getInstance($this->MODULE);
  124. $CNF = &$oModule->_oConfig->CNF;
  125. bx_import('BxTemplFunctions');
  126. bx_import('BxDolStorage');
  127. bx_import('BxDolImageTranscoder');
  128. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  129. $oTranscoder = BxDolImageTranscoder::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  130. $aGhostFiles = $oStorage->getGhosts ($aData[$CNF['FIELD_AUTHOR']], $aData[$CNF['FIELD_ID']]);
  131. if (!$aGhostFiles)
  132. return false;
  133. foreach ($aGhostFiles as $k => $a) {
  134. $isImage = $oTranscoder && (0 == strncmp('image/', $a['mime_type'], 6)); // preview for images only and transcoder object for preview must be defined
  135. $sUrlOriginal = $oStorage->getFileUrlById($a['id']);
  136. $sImgPopupId = 'bx-messages-atachment-popup-' . $a['id'];
  137. // images are displayed with preview and popup upon clicking
  138. $aGhostFiles[$k]['bx_if:image'] = array (
  139. 'condition' => $isImage,
  140. 'content' => array (
  141. 'url_original' => $sUrlOriginal,
  142. 'attr_file_name' => bx_html_attribute($a['file_name']),
  143. 'popup_id' => $sImgPopupId,
  144. 'url_preview' => $oTranscoder->getImageUrl($a['id']),
  145. 'popup' => BxTemplFunctions::getInstance()->transBox($sImgPopupId, '<img src="' . $sUrlOriginal . '" />', true, true),
  146. ),
  147. );
  148. // non-images are displayed as text links to original file
  149. $aGhostFiles[$k]['bx_if:not_image'] = array (
  150. 'condition' => !$isImage,
  151. 'content' => array (
  152. 'url_original' => $sUrlOriginal,
  153. 'attr_file_name' => bx_html_attribute($a['file_name']),
  154. 'file_name' => bx_process_output($a['file_name']),
  155. ),
  156. );
  157. }
  158. $aVars = array(
  159. 'bx_repeat:attachments' => $aGhostFiles,
  160. );
  161. return $this->parseHtmlByName('attachments.html', $aVars);
  162. }
  163. }
  164. /** @} */