BxNotesTemplate.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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, $sTemplateName = 'unit.html') {
  24. // get thumb url
  25. $sPhotoThumb = '';
  26. if ($aData[BxNotesConfig::$FIELD_THUMB]) {
  27. bx_import('BxDolImageTranscoder');
  28. $oImagesTranscoder = BxDolImageTranscoder::getObjectInstance(BxNotesConfig::$OBJECT_IMAGES_TRANSCODER_PREVIEW);
  29. if ($oImagesTranscoder)
  30. $sPhotoThumb = $oImagesTranscoder->getImageUrl($aData[BxNotesConfig::$FIELD_THUMB]);
  31. }
  32. // get note url
  33. bx_import('BxDolPermalinks');
  34. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=view-note&id=' . $aData['id']);
  35. bx_import('BxDolProfile');
  36. $oProfile = BxDolProfile::getInstance($aData['author']);
  37. if (!$oProfile) {
  38. bx_import('BxDolProfileUndefined');
  39. $oProfile = BxDolProfileUndefined::getInstance();
  40. }
  41. $sSummary = $aData['summary'];
  42. if (!$sSummary) {
  43. $iLimitChars = (int)getParam('bx_notes_summary_chars');
  44. $sSummary = trim(strip_tags($aData['text']));
  45. $sLinkMore = '';
  46. if (mb_strlen($sSummary) > $iLimitChars) {
  47. $sSummary = mb_substr($sSummary, 0, $iLimitChars);
  48. $sLinkMore = ' <a title="' . htmlspecialchars_adv(_t('_bx_notes_txt_read_more')) . '" href="' . $sUrl . '">&hellip;</a>';
  49. }
  50. $sSummary = htmlspecialchars_adv($sSummary) . $sLinkMore;
  51. }
  52. // generate html
  53. $aVars = array (
  54. 'id' => $aData['id'],
  55. 'content_url' => $sUrl,
  56. 'title' => bx_process_output($aData['title']),
  57. 'summary' => $sSummary,
  58. 'author' => $oProfile->getDisplayName(),
  59. 'author_url' => $oProfile->getUrl(),
  60. 'entry_posting_date' => bx_time_js($aData['added'], BX_FORMAT_DATE),
  61. 'bx_if:thumb' => array (
  62. 'condition' => $sPhotoThumb,
  63. 'content' => array (
  64. 'title' => bx_process_output($aData['title']),
  65. 'thumb_url' => $sPhotoThumb ? $sPhotoThumb : '',
  66. ),
  67. ),
  68. );
  69. return $this->parseHtmlByName($sTemplateName, $aVars);
  70. }
  71. function entryText ($aData, $sTemplateName = 'entry-text.html') {
  72. $aVars = $aData;
  73. $aVars['entry_title'] = $aData[BxNotesConfig::$FIELD_TITLE];
  74. $aVars['entry_text'] = $aData[BxNotesConfig::$FIELD_TEXT];
  75. return $this->parseHtmlByName($sTemplateName, $aVars);
  76. }
  77. function entryAuthor ($aData, $oProfile, $sTemplateName = 'author.html') {
  78. if (!$oProfile)
  79. return '';
  80. $aVars = array (
  81. 'author_url' => $oProfile->getUrl(),
  82. 'author_thumb_url' => $oProfile->getThumb(),
  83. 'author_title' => $oProfile->getDisplayName(),
  84. 'entry_posting_date' => bx_time_js($aData['added'], BX_FORMAT_DATE),
  85. );
  86. return $this->parseHtmlByName($sTemplateName, $aVars);
  87. }
  88. }
  89. /** @} */