BxBaseModTextTemplate.php 7.4 KB

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