oembed.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. require_once('./inc/header.inc.php');
  10. require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
  11. // used in oembed integration
  12. if (bx_get('l')){
  13. $aLinks = bx_get('l');
  14. bx_import('BxDolEmbed');
  15. $oEmbed = BxDolEmbed::getObjectInstance('sys_oembed');
  16. echoJson($oEmbed->parseLinks($aLinks));
  17. }
  18. // embedded representation of a URL on third party sites
  19. if (bx_get('url')){
  20. $sUrl = urldecode(bx_get('url'));
  21. $aUrl = parse_url($sUrl);
  22. $aUri = explode('/', $aUrl['path']);
  23. $aParams = [];
  24. parse_str($aUrl['query'], $aParams);
  25. if (!$aUri || empty($aUri[2]))
  26. echo 'no';
  27. $sContentInfoObject = BxDolPageQuery::getContentInfoObjectNameByURI($aUri[2]);
  28. $oContentInfo = BxDolContentInfo::getObjectInstance($sContentInfoObject);
  29. $sTitle = $oContentInfo->getContentTitle($aParams['id']);
  30. $iAuthor = $oContentInfo->getContentAuthor($aParams['id']);
  31. $oProfile = BxDolProfile::getInstance($iAuthor);
  32. $sAuthorName = $oProfile->getDisplayName();
  33. $sAuthorUrl = $oProfile->getUrl();
  34. $sHtml = $oContentInfo->getContentEmbed($aParams['id']);
  35. $sThumb = $oContentInfo->getContentThumb($aParams['id']);
  36. if (bx_get('format') == 'json'){
  37. $aResult = [
  38. 'version' => '1.0',
  39. 'type' => 'rich',
  40. 'title' => $sTitle,
  41. 'url' => $sUrl,
  42. 'author_name' => $sAuthorName,
  43. 'author_url' => $sAuthorUrl,
  44. 'url' => $sUrl,
  45. 'provider_name' => getParam('site_title'),
  46. 'provider_url' => BX_DOL_URL_ROOT,
  47. 'html' => $sHtml,
  48. ];
  49. if ($sThumb){
  50. $aResult['thumbnail_url'] = $sThumb;
  51. }
  52. header('Content-Type: application/json; charset=utf-8');
  53. echo json_encode($aResult);
  54. }
  55. }