1
0

BxBaseModTextTemplate.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BaseText Base classes for text modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Module representation.
  13. */
  14. class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
  15. {
  16. protected $_sUnitClassShowCase;
  17. function __construct(&$oConfig, &$oDb)
  18. {
  19. parent::__construct($oConfig, $oDb);
  20. $this->_sUnitClassShowCase = 'bx-base-unit-showcase bx-base-text-unit-showcase bx-def-margin-sec-bottom';
  21. }
  22. function unit ($aData, $isCheckPrivateContent = true, $sTemplateName = 'unit.html', $aParams = array())
  23. {
  24. $sResult = $this->checkPrivacy ($aData, $isCheckPrivateContent, $this->getModule(), $sTemplateName);
  25. if($sResult)
  26. return $sResult;
  27. return $this->parseHtmlByName($sTemplateName, $this->getUnit($aData, $aParams, $sTemplateName));
  28. }
  29. function entryAuthor ($aData, $iProfileId = false, $sFuncAuthorDesc = 'getAuthorDesc', $sTemplateName = 'author.html', $sFuncAuthorAddon = 'getAuthorAddon')
  30. {
  31. $CNF = &$this->getModule()->_oConfig->CNF;
  32. if (!$iProfileId)
  33. $iProfileId = $aData[$CNF['FIELD_AUTHOR']];
  34. $oProfile = BxDolProfile::getInstance($iProfileId);
  35. if (!$oProfile)
  36. $oProfile = BxDolProfileUndefined::getInstance();
  37. if (!$oProfile)
  38. return '';
  39. $sName = $oProfile->getDisplayName();
  40. $sAddon = $sFuncAuthorAddon ? $this->$sFuncAuthorAddon($aData, $oProfile) : '';
  41. $aVars = array (
  42. 'author_url' => $oProfile->getUrl(),
  43. 'author_thumb_url' => $oProfile->getThumb(),
  44. 'author_unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  45. 'author_title' => $sName,
  46. 'author_title_attr' => bx_html_attribute($sName),
  47. 'author_desc' => $sFuncAuthorDesc ? $this->$sFuncAuthorDesc($aData) : '',
  48. 'bx_if:addon' => array (
  49. 'condition' => (bool)$sAddon,
  50. 'content' => array (
  51. 'content' => $sAddon,
  52. ),
  53. ),
  54. );
  55. return $this->parseHtmlByName($sTemplateName, $aVars);
  56. }
  57. function getAuthorDesc ($aData)
  58. {
  59. return '';
  60. }
  61. function getAuthorAddon ($aData, $oProfile)
  62. {
  63. $CNF = &$this->getModule()->_oConfig->CNF;
  64. $sUrl = 'page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id=' . $oProfile->id();
  65. $sUrl = BxDolPermalinks::getInstance()->permalink($sUrl);
  66. return _t($CNF['T']['txt_all_entries_by'], $sUrl, $oProfile->getDisplayName(), $this->getModule()->_oDb->getEntriesNumByAuthor($oProfile->id()));
  67. }
  68. public function entryBreadcrumb($aContentInfo, $aTmplVarsItems = array())
  69. {
  70. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  71. return $this->parseHtmlByName('breadcrumb.html', array(
  72. 'url_home' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']),
  73. 'icon_home' => $CNF['ICON'],
  74. 'bx_repeat:items' => $aTmplVarsItems
  75. ));
  76. }
  77. protected function checkPrivacy ($aData, $isCheckPrivateContent, $oModule, $sTemplateName = '')
  78. {
  79. if ($isCheckPrivateContent && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $oModule->checkAllowedView($aData))) {
  80. $aVars = array (
  81. 'summary' => $sMsg,
  82. );
  83. return $this->parseHtmlByName($sTemplateName ? str_replace('.html', '_private.html', $sTemplateName) : 'unit_private.html', $aVars);
  84. }
  85. return '';
  86. }
  87. protected function getUnitThumbAndGallery ($aData)
  88. {
  89. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  90. $sPhotoThumb = '';
  91. $sPhotoGallery = '';
  92. if(!empty($CNF['FIELD_THUMB']) && !empty($aData[$CNF['FIELD_THUMB']])) {
  93. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  94. if ($oImagesTranscoder)
  95. $sPhotoThumb = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  96. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  97. if ($oImagesTranscoder)
  98. $sPhotoGallery = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  99. else
  100. $sPhotoGallery = $sPhotoThumb;
  101. }
  102. return array($sPhotoThumb, $sPhotoGallery);
  103. }
  104. protected function getUnit ($aData, $aParams = array(), $sTemplateName = 'unit.html')
  105. {
  106. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  107. // get thumb url
  108. list($sPhotoThumb, $sPhotoGallery) = $this->getUnitThumbAndGallery($aData);
  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. $sTitle = $this->getTitle($aData);
  115. $sText = $this->getText($aData);
  116. $sSummary = $this->getSummary($aData, $sTitle, $sText, $sUrl);
  117. $sSummaryPlain = isset($CNF['PARAM_CHARS_SUMMARY_PLAIN']) && $CNF['PARAM_CHARS_SUMMARY_PLAIN'] ? BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($sSummary), (int)getParam($CNF['PARAM_CHARS_SUMMARY_PLAIN'])) : '';
  118. if(!empty($CNF['OBJECT_METATAGS'])) {
  119. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  120. $sText = $oMetatags->metaParse($aData[$CNF['FIELD_ID']], $sText);
  121. }
  122. $sTitle = bx_process_output($sTitle);
  123. $aTmplVarsMeta = array();
  124. if(!empty($CNF['OBJECT_MENU_SNIPPET_META'])) {
  125. $oMenuMeta = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this);
  126. if($oMenuMeta) {
  127. $oMenuMeta->setContentId($aData[$CNF['FIELD_ID']]);
  128. $aTmplVarsMeta = array(
  129. 'meta' => $oMenuMeta->getCode()
  130. );
  131. }
  132. }
  133. // generate html
  134. return array (
  135. 'class' => $this->_getUnitClass($aData, $sTemplateName),
  136. 'id' => $aData[$CNF['FIELD_ID']],
  137. 'content_url' => $sUrl,
  138. 'title' => $sTitle,
  139. 'title_attr' => bx_html_attribute($sTitle),
  140. 'summary' => $sSummary,
  141. 'text' => $sText,
  142. 'author' => $oProfile->getDisplayName(),
  143. 'author_url' => $oProfile->getUrl(),
  144. 'author_icon' => $oProfile->getIcon(),
  145. 'author_thumb' => $oProfile->getThumb(),
  146. 'author_avatar' => $oProfile->getAvatar(),
  147. 'entry_posting_date' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE),
  148. 'module_name' => _t($CNF['T']['txt_sample_single']),
  149. 'ts' => $aData[$CNF['FIELD_ADDED']],
  150. 'bx_if:meta' => array(
  151. 'condition' => !empty($aTmplVarsMeta),
  152. 'content' => $aTmplVarsMeta
  153. ),
  154. 'bx_if:thumb' => array (
  155. 'condition' => $sPhotoThumb,
  156. 'content' => array (
  157. 'title' => $sTitle,
  158. 'summary_attr' => bx_html_attribute($sSummaryPlain),
  159. 'content_url' => $sUrl,
  160. 'thumb_url' => $sPhotoThumb ? $sPhotoThumb : '',
  161. 'gallery_url' => $sPhotoGallery ? $sPhotoGallery : '',
  162. 'strecher' => str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', 40),
  163. ),
  164. ),
  165. 'bx_if:no_thumb' => array (
  166. 'condition' => !$sPhotoThumb,
  167. 'content' => array (
  168. 'content_url' => $sUrl,
  169. 'summary_plain' => $sSummaryPlain,
  170. 'strecher' => mb_strlen($sSummaryPlain) > 240 ? '' : str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', round((240 - mb_strlen($sSummaryPlain)) / 6)),
  171. ),
  172. ),
  173. );
  174. }
  175. protected function getTitle($aData)
  176. {
  177. $CNF = &$this->getModule()->_oConfig->CNF;
  178. return isset($aData[$CNF['FIELD_TITLE']]) ? $aData[$CNF['FIELD_TITLE']] : '';
  179. }
  180. protected function getText($aData)
  181. {
  182. $CNF = &$this->getModule()->_oConfig->CNF;
  183. return isset($aData[$CNF['FIELD_TEXT']]) ? $aData[$CNF['FIELD_TEXT']] : '';
  184. }
  185. protected function getSummary($aData, $sTitle = '', $sText = '', $sUrl = '')
  186. {
  187. $CNF = &$this->getModule()->_oConfig->CNF;
  188. if(empty($CNF['PARAM_CHARS_SUMMARY']))
  189. return '';
  190. // get summary
  191. $sLinkMore = ' <a title="' . bx_html_attribute(_t('_sys_read_more', $sTitle)) . '" href="' . $sUrl . '"><i class="sys-icon ellipsis-h"></i></a>';
  192. return strmaxtextlen($sText, (int)getParam($CNF['PARAM_CHARS_SUMMARY']), $sLinkMore);
  193. }
  194. protected function _getUnitClass($aData, $sTemplateName = 'unit.html')
  195. {
  196. $sResult = '';
  197. switch($sTemplateName) {
  198. case 'unit_showcase.html':
  199. $sResult = $this->_sUnitClassShowCase;
  200. break;
  201. }
  202. return $sResult;
  203. }
  204. }
  205. /** @} */