BxNotesTemplate.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. // generate html
  60. $aVars = array (
  61. 'id' => $aData['id'],
  62. 'content_url' => $sUrl,
  63. 'title' => bx_process_output($aData['title']),
  64. 'summary' => $sSummary,
  65. 'author' => $oProfile->getDisplayName(),
  66. 'author_url' => $oProfile->getUrl(),
  67. 'entry_posting_date' => bx_time_js($aData['added'], BX_FORMAT_DATE),
  68. 'bx_if:thumb' => array (
  69. 'condition' => $sPhotoThumb,
  70. 'content' => array (
  71. 'title' => bx_process_output($aData['title']),
  72. 'thumb_url' => $sPhotoThumb ? $sPhotoThumb : '',
  73. ),
  74. ),
  75. );
  76. return $this->parseHtmlByName($sTemplateName, $aVars);
  77. }
  78. function entryText ($aData, $sTemplateName = 'entry-text.html') {
  79. $aVars = $aData;
  80. $aVars['entry_title'] = $aData[BxNotesConfig::$FIELD_TITLE];
  81. $aVars['entry_text'] = $aData[BxNotesConfig::$FIELD_TEXT];
  82. return $this->parseHtmlByName($sTemplateName, $aVars);
  83. }
  84. function entryAuthor ($aData, $oProfile, $sTemplateName = 'author.html') {
  85. if (!$oProfile)
  86. return '';
  87. $aVars = array (
  88. 'author_url' => $oProfile->getUrl(),
  89. 'author_thumb_url' => $oProfile->getThumb(),
  90. 'author_title' => $oProfile->getDisplayName(),
  91. 'entry_posting_date' => bx_time_js($aData['added'], BX_FORMAT_DATE),
  92. );
  93. return $this->parseHtmlByName($sTemplateName, $aVars);
  94. }
  95. }
  96. /** @} */