BxBaseModTextTemplate.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. $aParams['template_name'] = $sTemplateName;
  28. return $this->parseHtmlByName($sTemplateName, $this->getUnit($aData, $aParams));
  29. }
  30. function entryAuthor ($aData, $iProfileId = false, $sFuncAuthorDesc = 'getAuthorDesc', $sTemplateName = 'author.html', $sFuncAuthorAddon = 'getAuthorAddon')
  31. {
  32. $CNF = &$this->getModule()->_oConfig->CNF;
  33. if (!$iProfileId)
  34. $iProfileId = $aData[$CNF['FIELD_AUTHOR']];
  35. $oProfile = BxDolProfile::getInstance($iProfileId);
  36. if (!$oProfile)
  37. $oProfile = BxDolProfileUndefined::getInstance();
  38. if (!$oProfile)
  39. return '';
  40. $sName = $oProfile->getDisplayName();
  41. $sAddon = $sFuncAuthorAddon ? $this->$sFuncAuthorAddon($aData, $oProfile) : '';
  42. $aVars = array (
  43. 'author_url' => $oProfile->getUrl(),
  44. 'author_thumb_url' => $oProfile->getThumb(),
  45. 'author_unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  46. 'author_title' => $sName,
  47. 'author_title_attr' => bx_html_attribute($sName),
  48. 'author_desc' => $sFuncAuthorDesc ? $this->$sFuncAuthorDesc($aData) : '',
  49. 'bx_if:addon' => array (
  50. 'condition' => (bool)$sAddon,
  51. 'content' => array (
  52. 'content' => $sAddon,
  53. ),
  54. ),
  55. );
  56. return $this->parseHtmlByName($sTemplateName, $aVars);
  57. }
  58. function entryContext ($aData, $iProfileId = false, $sFuncContextDesc = 'getContextDesc', $sTemplateName = 'context.html', $sFuncContextAddon = 'getContextAddon')
  59. {
  60. $CNF = &$this->getModule()->_oConfig->CNF;
  61. $iContextId = $aData[$CNF['FIELD_ALLOW_VIEW_TO']];
  62. if ($iContextId >= 0)
  63. return '';
  64. $iProfileId = - $iContextId;
  65. $oProfile = BxDolProfile::getInstance($iProfileId);
  66. if (!$oProfile)
  67. $oProfile = BxDolProfileUndefined::getInstance();
  68. if (!$oProfile)
  69. return '';
  70. $sName = $oProfile->getDisplayName();
  71. $sAddon = $sFuncContextAddon ? $this->$sFuncContextAddon($aData, $oProfile) : '';
  72. $aVars = array (
  73. 'author_url' => $oProfile->getUrl(),
  74. 'author_thumb_url' => $oProfile->getThumb(),
  75. 'author_unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  76. 'author_title' => $sName,
  77. 'author_title_attr' => bx_html_attribute($sName),
  78. 'author_desc' => $sFuncContextDesc ? $this->$sFuncContextDesc($aData) : '',
  79. 'bx_if:addon' => array (
  80. 'condition' => (bool)$sAddon,
  81. 'content' => array (
  82. 'content' => $sAddon,
  83. ),
  84. ),
  85. );
  86. return $this->parseHtmlByName($sTemplateName, $aVars);
  87. }
  88. function getAuthorDesc ($aData)
  89. {
  90. return '';
  91. }
  92. function getContextDesc ($aData)
  93. {
  94. return '';
  95. }
  96. function getAuthorAddon ($aData, $oProfile)
  97. {
  98. $CNF = &$this->getModule()->_oConfig->CNF;
  99. $sUrl = 'page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id=' . $oProfile->id();
  100. $sUrl = BxDolPermalinks::getInstance()->permalink($sUrl);
  101. return _t($CNF['T']['txt_all_entries_by'], $sUrl, $oProfile->getDisplayName(), $this->getModule()->_oDb->getEntriesNumByAuthor($oProfile->id()));
  102. }
  103. function getContextAddon ($aData, $oProfile)
  104. {
  105. $CNF = &$this->getModule()->_oConfig->CNF;
  106. $sUrl = 'page.php?i=' . $CNF['URI_ENTRIES_BY_CONTEXT'] . '&profile_id=' . $oProfile->id();
  107. $sUrl = BxDolPermalinks::getInstance()->permalink($sUrl);
  108. return _t($CNF['T']['txt_all_entries_in'], $sUrl, $oProfile->getDisplayName(), $this->getModule()->_oDb->getEntriesNumByContext($oProfile->id()));
  109. }
  110. public function entryBreadcrumb($aContentInfo, $aTmplVarsItems = array())
  111. {
  112. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  113. return $this->parseHtmlByName('breadcrumb.html', array(
  114. 'url_home' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']),
  115. 'icon_home' => $CNF['ICON'],
  116. 'bx_repeat:items' => $aTmplVarsItems
  117. ));
  118. }
  119. protected function checkPrivacy ($aData, $isCheckPrivateContent, $oModule, $sTemplateName = '')
  120. {
  121. if ($isCheckPrivateContent && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $oModule->checkAllowedView($aData))) {
  122. $aVars = array (
  123. 'summary' => $sMsg,
  124. );
  125. return $this->parseHtmlByName($sTemplateName ? str_replace('.html', '_private.html', $sTemplateName) : 'unit_private.html', $aVars);
  126. }
  127. return '';
  128. }
  129. protected function getUnitThumbAndGallery ($aData)
  130. {
  131. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  132. $sPhotoThumb = '';
  133. $sPhotoGallery = '';
  134. if(!empty($CNF['FIELD_THUMB']) && !empty($aData[$CNF['FIELD_THUMB']])) {
  135. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  136. if ($oImagesTranscoder)
  137. $sPhotoThumb = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  138. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  139. if ($oImagesTranscoder)
  140. $sPhotoGallery = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  141. else
  142. $sPhotoGallery = $sPhotoThumb;
  143. }
  144. return array($sPhotoThumb, $sPhotoGallery);
  145. }
  146. protected function getUnit ($aData, $aParams = array())
  147. {
  148. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  149. // get thumb url
  150. list($sPhotoThumb, $sPhotoGallery) = $this->getUnitThumbAndGallery($aData);
  151. // get entry url
  152. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]);
  153. $oProfile = BxDolProfile::getInstance($aData[$CNF['FIELD_AUTHOR']]);
  154. if (!$oProfile)
  155. $oProfile = BxDolProfileUndefined::getInstance();
  156. $sTitle = $this->getTitle($aData);
  157. $sText = $this->getText($aData);
  158. $sSummary = $this->getSummary($aData, $sTitle, $sText, $sUrl);
  159. $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'])) : '';
  160. if(!empty($CNF['OBJECT_METATAGS'])) {
  161. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  162. $sText = $oMetatags->metaParse($aData[$CNF['FIELD_ID']], $sText);
  163. }
  164. $sTitle = bx_process_output($sTitle);
  165. $aTmplVarsMeta = array();
  166. if(!empty($CNF['OBJECT_MENU_SNIPPET_META'])) {
  167. $oMenuMeta = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this);
  168. if($oMenuMeta) {
  169. $oMenuMeta->setContentId($aData[$CNF['FIELD_ID']]);
  170. $aTmplVarsMeta = array(
  171. 'meta' => $oMenuMeta->getCode()
  172. );
  173. }
  174. }
  175. // generate html
  176. return array (
  177. 'class' => $this->_getUnitClass($aData,(isset($aParams['template_name']) ? $aParams['template_name'] : '')),
  178. 'id' => $aData[$CNF['FIELD_ID']],
  179. 'content_url' => $sUrl,
  180. 'title' => $sTitle,
  181. 'title_attr' => bx_html_attribute($sTitle),
  182. 'summary' => $sSummary,
  183. 'text' => $sText,
  184. 'author' => $oProfile->getDisplayName(),
  185. 'author_url' => $oProfile->getUrl(),
  186. 'author_icon' => $oProfile->getIcon(),
  187. 'author_thumb' => $oProfile->getThumb(),
  188. 'author_avatar' => $oProfile->getAvatar(),
  189. 'entry_posting_date' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE),
  190. 'module_name' => _t($CNF['T']['txt_sample_single']),
  191. 'ts' => $aData[$CNF['FIELD_ADDED']],
  192. 'bx_if:meta' => array(
  193. 'condition' => !empty($aTmplVarsMeta),
  194. 'content' => $aTmplVarsMeta
  195. ),
  196. 'bx_if:thumb' => array (
  197. 'condition' => $sPhotoThumb,
  198. 'content' => array (
  199. 'title' => $sTitle,
  200. 'summary_attr' => bx_html_attribute($sSummaryPlain),
  201. 'content_url' => $sUrl,
  202. 'thumb_url' => $sPhotoThumb ? $sPhotoThumb : '',
  203. 'gallery_url' => $sPhotoGallery ? $sPhotoGallery : '',
  204. 'strecher' => str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', 40),
  205. ),
  206. ),
  207. 'bx_if:no_thumb' => array (
  208. 'condition' => !$sPhotoThumb,
  209. 'content' => array (
  210. 'content_url' => $sUrl,
  211. 'summary_plain' => $sSummaryPlain,
  212. 'strecher' => mb_strlen($sSummaryPlain) > 240 ? '' : str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', round((240 - mb_strlen($sSummaryPlain)) / 6)),
  213. ),
  214. ),
  215. );
  216. }
  217. protected function getTitle($aData)
  218. {
  219. $CNF = &$this->getModule()->_oConfig->CNF;
  220. return isset($aData[$CNF['FIELD_TITLE']]) ? $aData[$CNF['FIELD_TITLE']] : '';
  221. }
  222. protected function getText($aData)
  223. {
  224. $CNF = &$this->getModule()->_oConfig->CNF;
  225. return isset($aData[$CNF['FIELD_TEXT']]) ? $aData[$CNF['FIELD_TEXT']] : '';
  226. }
  227. protected function getSummary($aData, $sTitle = '', $sText = '', $sUrl = '')
  228. {
  229. $CNF = &$this->getModule()->_oConfig->CNF;
  230. if(empty($CNF['PARAM_CHARS_SUMMARY']))
  231. return '';
  232. // get summary
  233. $sLinkMore = ' <a title="' . bx_html_attribute(_t('_sys_read_more', $sTitle)) . '" href="' . $sUrl . '"><i class="sys-icon ellipsis-h"></i></a>';
  234. return strmaxtextlen($sText, (int)getParam($CNF['PARAM_CHARS_SUMMARY']), $sLinkMore);
  235. }
  236. protected function _getUnitClass($aData, $sTemplateName = 'unit.html')
  237. {
  238. $sResult = '';
  239. switch($sTemplateName) {
  240. case 'unit_showcase.html':
  241. $sResult = $this->_sUnitClassShowCase;
  242. break;
  243. }
  244. return $sResult;
  245. }
  246. }
  247. /** @} */