BxBaseModTextTemplate.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 static $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(self::$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(self::$MODULE);
  96. $CNF = &$oModule->_oConfig->CNF;
  97. $aVars = $aData;
  98. $aVars['entry_title'] = $aData[$CNF['FIELD_TITLE']];
  99. $aVars['entry_text'] = $aData[$CNF['FIELD_TEXT']];
  100. return $this->parseHtmlByName($sTemplateName, $aVars);
  101. }
  102. function entryAuthor ($aData, $oProfile, $sTemplateName = 'author.html')
  103. {
  104. if (!$oProfile)
  105. return '';
  106. $oModule = BxDolModule::getInstance(self::$MODULE);
  107. $CNF = &$oModule->_oConfig->CNF;
  108. $aVars = array (
  109. 'author_url' => $oProfile->getUrl(),
  110. 'author_thumb_url' => $oProfile->getThumb(),
  111. 'author_title' => $oProfile->getDisplayName(),
  112. 'entry_posting_date' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE),
  113. );
  114. return $this->parseHtmlByName($sTemplateName, $aVars);
  115. }
  116. }
  117. /** @} */