BxBaseEmbedIframely.php 2.2 KB

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