BxDolEmbed.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 UnaCore UNA Core
  7. * @{
  8. */
  9. /**
  10. * Embed provider.
  11. *
  12. * Create an embed from a link.
  13. *
  14. * @section editor_create Creating the Editor object:
  15. *
  16. *
  17. * Add record to 'sys_objects_embeds' table:
  18. *
  19. * - object: name of the embed object, in the format: vendor prefix, underscore, module prefix, underscore, internal identifier or nothing
  20. * - title: title of the embed provider, dmay be isplayed in the Studio.
  21. * - override_class_name: user defined class name which is derived from one of base editor classes.
  22. * - override_class_file: the location of the user defined class, leave it empty if class is located in system folders.
  23. *
  24. *
  25. * @section example Example of usage
  26. *
  27. * Generate HTML for a link which will be converted to an embed later:
  28. *
  29. * @code
  30. * $oEmbed = BxDolEmbed::getObjectInstance(); // get default embed object instance
  31. * if ($oEmbed) // check if editor is available for using
  32. * echo $oEmbed->getLinkHTML ('https://una.io', 'UNA.IO'); // output HTML which will be automatically converted into embed upon page load
  33. * else
  34. * echo '<a href="https://una.io">UNA.IO</a>';
  35. * @endcode
  36. *
  37. */
  38. class BxDolEmbed extends BxDolFactoryObject
  39. {
  40. protected $_bCssJsAdded = false;
  41. /**
  42. * Get editor object instance by object name
  43. * @param $sObject object name
  44. * @return object instance or false on error
  45. */
  46. static public function getObjectInstance($sObject = false, $oTemplate = false)
  47. {
  48. if (!$sObject)
  49. $sObject = getParam('sys_embed_default');
  50. return parent::getObjectInstanceByClassNames($sObject, $oTemplate, 'BxDolEmbed', 'BxDolEmbedQuery');
  51. }
  52. /**
  53. * Print HTML which will be automatically converted into embed upon page load
  54. * @param $sLink - link
  55. * @param $sTitle - title or use link for the title if omitted
  56. * @param $sMaxWidth - try to restrict max width of embed (works in supported embed providers only)
  57. */
  58. public function getLinkHTML ($sLink, $sTitle = '', $sMaxWidth = '')
  59. {
  60. // override this function in particular editor class
  61. }
  62. /**
  63. * Add css/js files which are needed for embed display and functionality.
  64. */
  65. public function addJsCss ()
  66. {
  67. // override this function in particular editor class
  68. }
  69. }
  70. /** @} */