BxBaseEmbedIframely.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 BxBaseEmbedIframely extends BxDolEmbed
  14. {
  15. public function __construct ($aObject, $oTemplate)
  16. {
  17. $this->_sTableData = 'sys_iframely_data';
  18. parent::__construct ($aObject, $oTemplate);
  19. }
  20. public function getLinkHTML ($sLink, $sTitle = '', $sMaxWidth = '')
  21. {
  22. $aAttrs = array(
  23. 'title' => bx_html_attribute($sTitle),
  24. );
  25. // check for external link
  26. if (strncmp(BX_DOL_URL_ROOT, $sLink, strlen(BX_DOL_URL_ROOT)) !== 0) {
  27. $aAttrs['target'] = '_blank';
  28. if (getParam('sys_add_nofollow') == 'on')
  29. $aAttrs['rel'] = 'nofollow';
  30. }
  31. return $this->_oTemplate->parseHtmlByName('embed_iframely_link.html', array(
  32. 'link' => $sLink,
  33. 'title' => $sTitle,
  34. 'attrs' => bx_convert_array2attrs($aAttrs),
  35. 'width' => $sMaxWidth,
  36. ));
  37. }
  38. public function addProcessLinkMethod ()
  39. {
  40. return "
  41. <script>
  42. function bx_embed_link(e)
  43. {
  44. window.iframely && iframely.load(e);
  45. }
  46. </script>";
  47. }
  48. public function addJsCss ()
  49. {
  50. if ($this->_bCssJsAdded)
  51. return '';
  52. $sKey = getParam('sys_iframely_api_key');
  53. $this->_bCssJsAdded = true;
  54. return $this->_oTemplate->parseHtmlByName('embed_iframely_integration.html', array(
  55. 'key' => $sKey,
  56. ));
  57. }
  58. public function getDataFromApi ($sUrl, $sTheme)
  59. {
  60. return bx_file_get_contents("https://iframe.ly/api/oembed?theme=" . $sTheme . "&url=" . $sUrl . "&api_key=" . getParam('sys_iframely_api_key') . "&card=small&media=0");
  61. }
  62. public function getDataHtml ($sUrl, $sTheme)
  63. {
  64. $aData = $this->getData($sUrl, $sTheme);
  65. return $aData['html'];
  66. }
  67. }
  68. /** @} */