BxNotesTemplate.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 Notes Notes
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolModuleTemplate');
  12. /*
  13. * Notes module representation.
  14. */
  15. class BxNotesTemplate extends BxDolModuleTemplate {
  16. /**
  17. * Constructor
  18. */
  19. function __construct(&$oConfig, &$oDb) {
  20. parent::__construct($oConfig, $oDb);
  21. $this->addCss ('main.css');
  22. }
  23. function unit ($aData, $isCheckPrivateContent = true, $sTemplateName = 'unit.html') {
  24. $oModule = BxDolModule::getInstance('bx_notes');
  25. if ($isCheckPrivateContent && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $oModule->isAllowedView($aData))) {
  26. $aVars = array (
  27. 'summary' => $sMsg,
  28. );
  29. return $this->parseHtmlByName('unit_private.html', $aVars);
  30. }
  31. // get thumb url
  32. $sPhotoThumb = '';
  33. if ($aData[BxNotesConfig::$FIELD_THUMB]) {
  34. bx_import('BxDolImageTranscoder');
  35. $oImagesTranscoder = BxDolImageTranscoder::getObjectInstance(BxNotesConfig::$OBJECT_IMAGES_TRANSCODER_PREVIEW);
  36. if ($oImagesTranscoder)
  37. $sPhotoThumb = $oImagesTranscoder->getImageUrl($aData[BxNotesConfig::$FIELD_THUMB]);
  38. }
  39. // get note url
  40. bx_import('BxDolPermalinks');
  41. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=view-note&id=' . $aData['id']);
  42. bx_import('BxDolProfile');
  43. $oProfile = BxDolProfile::getInstance($aData['author']);
  44. if (!$oProfile) {
  45. bx_import('BxDolProfileUndefined');
  46. $oProfile = BxDolProfileUndefined::getInstance();
  47. }
  48. $sSummary = $aData['summary'];
  49. if (!$sSummary) {
  50. $iLimitChars = (int)getParam('bx_notes_summary_chars');
  51. $sSummary = trim(strip_tags($aData['text']));
  52. $sLinkMore = '';
  53. if (mb_strlen($sSummary) > $iLimitChars) {
  54. $sSummary = mb_substr($sSummary, 0, $iLimitChars);
  55. $sLinkMore = ' <a title="' . bx_html_attribute(_t('_bx_notes_txt_read_more', $aData['title'])) . '" href="' . $sUrl . '"><i class="sys-icon ellipsis-horizontal"></i></a>';
  56. }
  57. $sSummary = htmlspecialchars_adv($sSummary) . $sLinkMore;
  58. }
  59. $sSummaryPlain = BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($sSummary), 280);
  60. // generate html
  61. $aVars = array (
  62. 'id' => $aData['id'],
  63. 'content_url' => $sUrl,
  64. 'title' => bx_process_output($aData['title']),
  65. 'summary' => $sSummary,
  66. 'author' => $oProfile->getDisplayName(),
  67. 'author_url' => $oProfile->getUrl(),
  68. 'entry_posting_date' => bx_time_js($aData['added'], BX_FORMAT_DATE),
  69. 'bx_if:thumb' => array (
  70. 'condition' => $sPhotoThumb,
  71. 'content' => array (
  72. 'title' => bx_process_output($aData['title']),
  73. 'summary_attr' => bx_html_attribute($sSummaryPlain),
  74. 'content_url' => $sUrl,
  75. 'thumb_url' => $sPhotoThumb ? $sPhotoThumb : '',
  76. ),
  77. ),
  78. 'bx_if:no_thumb' => array (
  79. 'condition' => !$sPhotoThumb,
  80. 'content' => array (
  81. 'content_url' => $sUrl,
  82. 'summary_plain' => $sSummaryPlain,
  83. ),
  84. ),
  85. );
  86. return $this->parseHtmlByName($sTemplateName, $aVars);
  87. }
  88. function entryText ($aData, $sTemplateName = 'entry-text.html') {
  89. $aVars = $aData;
  90. $aVars['entry_title'] = $aData[BxNotesConfig::$FIELD_TITLE];
  91. $aVars['entry_text'] = $aData[BxNotesConfig::$FIELD_TEXT];
  92. return $this->parseHtmlByName($sTemplateName, $aVars);
  93. }
  94. function entryAuthor ($aData, $oProfile, $sTemplateName = 'author.html') {
  95. if (!$oProfile)
  96. return '';
  97. $aVars = array (
  98. 'author_url' => $oProfile->getUrl(),
  99. 'author_thumb_url' => $oProfile->getThumb(),
  100. 'author_title' => $oProfile->getDisplayName(),
  101. 'entry_posting_date' => bx_time_js($aData['added'], BX_FORMAT_DATE),
  102. );
  103. return $this->parseHtmlByName($sTemplateName, $aVars);
  104. }
  105. }
  106. /** @} */