BxBaseEmbedEmbedly.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Iframely integration.
  11. * @see BxDolEmbed
  12. */
  13. class BxBaseEmbedEmbedly extends BxDolEmbed
  14. {
  15. public function __construct ($aObject, $oTemplate)
  16. {
  17. parent::__construct ($aObject);
  18. if ($oTemplate)
  19. $this->_oTemplate = $oTemplate;
  20. else
  21. $this->_oTemplate = BxDolTemplate::getInstance();
  22. }
  23. public function getLinkHTML ($sLink, $sTitle = '', $sMaxWidth = '', $sTheme = '')
  24. {
  25. $aAttrs = array(
  26. 'title' => bx_html_attribute($sTitle)
  27. );
  28. if ($sTheme != ''){
  29. $aAttrs['data-card-theme'] = $sTheme;
  30. }
  31. // check for external link
  32. if (strncmp(BX_DOL_URL_ROOT, $sLink, strlen(BX_DOL_URL_ROOT)) !== 0) {
  33. $aAttrs['target'] = '_blank';
  34. if (getParam('sys_add_nofollow') == 'on')
  35. $aAttrs['rel'] = 'nofollow';
  36. }
  37. return $this->_oTemplate->parseHtmlByName('embed_embedly_link.html', array(
  38. 'link' => $sLink,
  39. 'title' => $sTitle,
  40. 'attrs' => bx_convert_array2attrs($aAttrs),
  41. 'width' => $sMaxWidth,
  42. ));
  43. }
  44. public function addProcessLinkMethod ()
  45. {
  46. return "
  47. <script>
  48. function bx_embed_link(e)
  49. {
  50. embedly('card', e);
  51. }
  52. </script>";
  53. }
  54. public function addJsCss ()
  55. {
  56. if ($this->_bCssJsAdded)
  57. return '';
  58. $sKey = getParam('sys_embedly_api_key');
  59. $this->_bCssJsAdded = true;
  60. return $this->_oTemplate->parseHtmlByName('embed_embedly_integration.html', array(
  61. 'bx_if:key' => array (
  62. 'condition' => !empty($sKey),
  63. 'content' => array('key' => $sKey),
  64. )
  65. ));
  66. }
  67. }
  68. /** @} */