BxBaseModTextTemplate.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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('BxDolTranscoderImage');
  35. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  36. if ($oImagesTranscoder)
  37. $sPhotoThumb = $oImagesTranscoder->getFileUrl($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. // get summary
  49. $sLinkMore = ' <a title="' . bx_html_attribute(_t('_sys_read_more', $aData[$CNF['FIELD_TITLE']])) . '" href="' . $sUrl . '"><i class="sys-icon ellipsis-h"></i></a>';
  50. $sSummary = strmaxtextlen($aData[$CNF['FIELD_TEXT']], (int)getParam($CNF['PARAM_CHARS_SUMMARY']), $sLinkMore);
  51. $sSummaryPlain = BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($sSummary), (int)getParam($CNF['PARAM_CHARS_SUMMARY_PLAIN']));
  52. // generate html
  53. $aVars = array (
  54. 'id' => $aData[$CNF['FIELD_ID']],
  55. 'content_url' => $sUrl,
  56. 'title' => bx_process_output($aData[$CNF['FIELD_TITLE']]),
  57. 'summary' => $sSummary,
  58. 'author' => $oProfile->getDisplayName(),
  59. 'author_url' => $oProfile->getUrl(),
  60. 'entry_posting_date' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE),
  61. 'module_name' => _t($CNF['T']['txt_sample_single']),
  62. 'ts' => $aData[$CNF['FIELD_ADDED']],
  63. 'bx_if:thumb' => array (
  64. 'condition' => $sPhotoThumb,
  65. 'content' => array (
  66. 'title' => bx_process_output($aData[$CNF['FIELD_TITLE']]),
  67. 'summary_attr' => bx_html_attribute($sSummaryPlain),
  68. 'content_url' => $sUrl,
  69. 'thumb_url' => $sPhotoThumb ? $sPhotoThumb : '',
  70. ),
  71. ),
  72. 'bx_if:no_thumb' => array (
  73. 'condition' => !$sPhotoThumb,
  74. 'content' => array (
  75. 'content_url' => $sUrl,
  76. 'summary_plain' => $sSummaryPlain,
  77. ),
  78. ),
  79. );
  80. return $this->parseHtmlByName($sTemplateName, $aVars);
  81. }
  82. function entryText ($aData, $sTemplateName = 'entry-text.html')
  83. {
  84. $oModule = BxDolModule::getInstance($this->MODULE);
  85. $CNF = &$oModule->_oConfig->CNF;
  86. $aVars = $aData;
  87. $aVars['entry_title'] = isset($aData[$CNF['FIELD_TITLE']]) ? $aData[$CNF['FIELD_TITLE']] : '';
  88. $aVars['entry_text'] = $aData[$CNF['FIELD_TEXT']];
  89. if (!empty($CNF['OBJECT_METATAGS'])) {
  90. bx_import('BxDolMetatags');
  91. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  92. $aVars['text'] = $oMetatags->keywordsParse($aData[$CNF['FIELD_ID']], $aVars['text']);
  93. }
  94. return $this->parseHtmlByName($sTemplateName, $aVars);
  95. }
  96. function entryLocation ($iContentId)
  97. {
  98. $oModule = BxDolModule::getInstance($this->MODULE);
  99. $CNF = &$oModule->_oConfig->CNF;
  100. if (empty($CNF['OBJECT_METATAGS']))
  101. return '';
  102. bx_import('BxDolMetatags');
  103. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  104. $aVars = array (
  105. 'location' => $oMetatags->locationsString($iContentId)
  106. );
  107. return $this->parseHtmlByName('entry-location.html', $aVars);
  108. }
  109. function entryAuthor ($aData, $sTemplateName = 'author.html')
  110. {
  111. $oModule = BxDolModule::getInstance($this->MODULE);
  112. $CNF = &$oModule->_oConfig->CNF;
  113. $oProfile = BxDolProfile::getInstance($aData[$CNF['FIELD_AUTHOR']]);
  114. if (!$oProfile) {
  115. bx_import('BxDolProfileUndefined');
  116. $oProfile = BxDolProfileUndefined::getInstance();
  117. }
  118. if (!$oProfile)
  119. return '';
  120. $aVars = array (
  121. 'author_url' => $oProfile->getUrl(),
  122. 'author_thumb_url' => $oProfile->getThumb(),
  123. 'author_title' => $oProfile->getDisplayName(),
  124. 'author_desc' => $this->getAuthorDesc($aData),
  125. );
  126. return $this->parseHtmlByName($sTemplateName, $aVars);
  127. }
  128. function getAuthorDesc ($aData)
  129. {
  130. $oModule = BxDolModule::getInstance($this->MODULE);
  131. return bx_time_js($aData[$oModule->_oConfig->CNF['FIELD_ADDED']], BX_FORMAT_DATE);
  132. }
  133. function entryAttachments ($aData)
  134. {
  135. $oModule = BxDolModule::getInstance($this->MODULE);
  136. $CNF = &$oModule->_oConfig->CNF;
  137. bx_import('BxTemplFunctions');
  138. bx_import('BxDolStorage');
  139. bx_import('BxDolTranscoderImage');
  140. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  141. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  142. $aGhostFiles = $oStorage->getGhosts ($aData[$CNF['FIELD_AUTHOR']], $aData[$CNF['FIELD_ID']]);
  143. if (!$aGhostFiles)
  144. return false;
  145. foreach ($aGhostFiles as $k => $a) {
  146. $isImage = $oTranscoder && (0 == strncmp('image/', $a['mime_type'], 6)); // preview for images only and transcoder object for preview must be defined
  147. $sUrlOriginal = $oStorage->getFileUrlById($a['id']);
  148. $sImgPopupId = 'bx-messages-atachment-popup-' . $a['id'];
  149. // images are displayed with preview and popup upon clicking
  150. $aGhostFiles[$k]['bx_if:image'] = array (
  151. 'condition' => $isImage,
  152. 'content' => array (
  153. 'url_original' => $sUrlOriginal,
  154. 'attr_file_name' => bx_html_attribute($a['file_name']),
  155. 'popup_id' => $sImgPopupId,
  156. 'url_preview' => $oTranscoder->getFileUrl($a['id']),
  157. 'popup' => BxTemplFunctions::getInstance()->transBox($sImgPopupId, '<img src="' . $sUrlOriginal . '" />', true, true),
  158. ),
  159. );
  160. // non-images are displayed as text links to original file
  161. $aGhostFiles[$k]['bx_if:not_image'] = array (
  162. 'condition' => !$isImage,
  163. 'content' => array (
  164. 'url_original' => $sUrlOriginal,
  165. 'attr_file_name' => bx_html_attribute($a['file_name']),
  166. 'file_name' => bx_process_output($a['file_name']),
  167. ),
  168. );
  169. }
  170. $aVars = array(
  171. 'bx_repeat:attachments' => $aGhostFiles,
  172. );
  173. return $this->parseHtmlByName('attachments.html', $aVars);
  174. }
  175. }
  176. /** @} */