BxNotesTemplate.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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('BxDolTwigTemplate');
  12. /*
  13. * Notes module representation.
  14. */
  15. class BxNotesTemplate extends BxDolTwigTemplate {
  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. 'when' => defineTimeInterval($aData['added']),
  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. }
  72. /** @} */