BxBaseModTextTemplate.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. 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(), $sTemplateName);
  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. $sName = $oProfile->getDisplayName();
  38. $sAddon = $sFuncAuthorAddon ? $this->$sFuncAuthorAddon($aData, $oProfile) : '';
  39. $aVars = array (
  40. 'author_url' => $oProfile->getUrl(),
  41. 'author_thumb_url' => $oProfile->getThumb(),
  42. 'author_unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  43. 'author_title' => $sName,
  44. 'author_title_attr' => bx_html_attribute($sName),
  45. 'author_desc' => $sFuncAuthorDesc ? $this->$sFuncAuthorDesc($aData) : '',
  46. 'bx_if:addon' => array (
  47. 'condition' => (bool)$sAddon,
  48. 'content' => array (
  49. 'content' => $sAddon,
  50. ),
  51. ),
  52. );
  53. return $this->parseHtmlByName($sTemplateName, $aVars);
  54. }
  55. function getAuthorDesc ($aData)
  56. {
  57. return '';
  58. }
  59. function getAuthorAddon ($aData, $oProfile)
  60. {
  61. $CNF = &$this->getModule()->_oConfig->CNF;
  62. $sUrl = 'page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id=' . $oProfile->id();
  63. $sUrl = BxDolPermalinks::getInstance()->permalink($sUrl);
  64. return _t($CNF['T']['txt_all_entries_by'], $sUrl, $oProfile->getDisplayName(), $this->getModule()->_oDb->getEntriesNumByAuthor($oProfile->id()));
  65. }
  66. public function entryBreadcrumb($aContentInfo, $aTmplVarsItems = array())
  67. {
  68. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  69. return $this->parseHtmlByName('breadcrumb.html', array(
  70. 'url_home' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']),
  71. 'icon_home' => $CNF['ICON'],
  72. 'bx_repeat:items' => $aTmplVarsItems
  73. ));
  74. }
  75. protected function checkPrivacy ($aData, $isCheckPrivateContent, $oModule, $sTemplateName = '')
  76. {
  77. if ($isCheckPrivateContent && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $oModule->checkAllowedView($aData))) {
  78. $aVars = array (
  79. 'summary' => $sMsg,
  80. );
  81. return $this->parseHtmlByName($sTemplateName ? str_replace('.html', '_private.html', $sTemplateName) : 'unit_private.html', $aVars);
  82. }
  83. return '';
  84. }
  85. protected function getUnitThumbAndGallery ($aData)
  86. {
  87. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  88. $sPhotoThumb = '';
  89. $sPhotoGallery = '';
  90. if(!empty($CNF['FIELD_THUMB']) && !empty($aData[$CNF['FIELD_THUMB']])) {
  91. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  92. if ($oImagesTranscoder)
  93. $sPhotoThumb = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  94. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  95. if ($oImagesTranscoder)
  96. $sPhotoGallery = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  97. else
  98. $sPhotoGallery = $sPhotoThumb;
  99. }
  100. return array($sPhotoThumb, $sPhotoGallery);
  101. }
  102. protected function getUnit ($aData, $aParams = array())
  103. {
  104. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  105. // get thumb url
  106. list($sPhotoThumb, $sPhotoGallery) = $this->getUnitThumbAndGallery($aData);
  107. // get entry url
  108. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]);
  109. $oProfile = BxDolProfile::getInstance($aData[$CNF['FIELD_AUTHOR']]);
  110. if (!$oProfile)
  111. $oProfile = BxDolProfileUndefined::getInstance();
  112. $sTitle = $this->getTitle($aData);
  113. $sText = $this->getText($aData);
  114. $sSummary = $this->getSummary($aData, $sTitle, $sText, $sUrl);
  115. $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'])) : '';
  116. if(!empty($CNF['OBJECT_METATAGS'])) {
  117. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  118. // keywords
  119. if ($oMetatags->keywordsIsEnabled())
  120. $sText = $oMetatags->keywordsParse($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. 'id' => $aData[$CNF['FIELD_ID']],
  136. 'content_url' => $sUrl,
  137. 'title' => $sTitle,
  138. 'title_attr' => bx_html_attribute($sTitle),
  139. 'summary' => $sSummary,
  140. 'text' => $sText,
  141. 'author' => $oProfile->getDisplayName(),
  142. 'author_url' => $oProfile->getUrl(),
  143. 'author_icon' => $oProfile->getIcon(),
  144. 'author_thumb' => $oProfile->getThumb(),
  145. 'author_avatar' => $oProfile->getAvatar(),
  146. 'entry_posting_date' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE),
  147. 'module_name' => _t($CNF['T']['txt_sample_single']),
  148. 'ts' => $aData[$CNF['FIELD_ADDED']],
  149. 'bx_if:meta' => array(
  150. 'condition' => !empty($aTmplVarsMeta),
  151. 'content' => $aTmplVarsMeta
  152. ),
  153. 'bx_if:thumb' => array (
  154. 'condition' => $sPhotoThumb,
  155. 'content' => array (
  156. 'title' => $sTitle,
  157. 'summary_attr' => bx_html_attribute($sSummaryPlain),
  158. 'content_url' => $sUrl,
  159. 'thumb_url' => $sPhotoThumb ? $sPhotoThumb : '',
  160. 'gallery_url' => $sPhotoGallery ? $sPhotoGallery : '',
  161. 'strecher' => str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', 40),
  162. ),
  163. ),
  164. 'bx_if:no_thumb' => array (
  165. 'condition' => !$sPhotoThumb,
  166. 'content' => array (
  167. 'content_url' => $sUrl,
  168. 'summary_plain' => $sSummaryPlain,
  169. 'strecher' => mb_strlen($sSummaryPlain) > 240 ? '' : str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', round((240 - mb_strlen($sSummaryPlain)) / 6)),
  170. ),
  171. ),
  172. );
  173. }
  174. protected function getTitle($aData)
  175. {
  176. $CNF = &$this->getModule()->_oConfig->CNF;
  177. return isset($aData[$CNF['FIELD_TITLE']]) ? $aData[$CNF['FIELD_TITLE']] : '';
  178. }
  179. protected function getText($aData)
  180. {
  181. $CNF = &$this->getModule()->_oConfig->CNF;
  182. return isset($aData[$CNF['FIELD_TEXT']]) ? $aData[$CNF['FIELD_TEXT']] : '';
  183. }
  184. protected function getSummary($aData, $sTitle = '', $sText = '', $sUrl = '')
  185. {
  186. $CNF = &$this->getModule()->_oConfig->CNF;
  187. if(empty($CNF['PARAM_CHARS_SUMMARY']))
  188. return '';
  189. // get summary
  190. $sLinkMore = ' <a title="' . bx_html_attribute(_t('_sys_read_more', $sTitle)) . '" href="' . $sUrl . '"><i class="sys-icon ellipsis-h"></i></a>';
  191. return strmaxtextlen($sText, (int)getParam($CNF['PARAM_CHARS_SUMMARY']), $sLinkMore);
  192. }
  193. }
  194. /** @} */