BxDolEmbed.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 BxDolFactory implements iBxDolFactoryObject
  39. {
  40. protected $_sObject;
  41. protected $_aObject;
  42. /**
  43. * Constructor
  44. * @param $aObject array of editor options
  45. */
  46. protected function __construct($aObject)
  47. {
  48. parent::__construct();
  49. $this->_sObject = $aObject['object'];
  50. $this->_aObject = $aObject;
  51. }
  52. /**
  53. * Get editor object instance by object name
  54. * @param $sObject object name
  55. * @return object instance or false on error
  56. */
  57. static public function getObjectInstance($sObject = false, $oTemplate = false)
  58. {
  59. if (!$sObject)
  60. $sObject = getParam('sys_embed_default');
  61. if (isset($GLOBALS['bxDolClasses']['BxDolEmbed!'.$sObject]))
  62. return $GLOBALS['bxDolClasses']['BxDolEmbed!'.$sObject];
  63. $aObject = BxDolEmbedQuery::getObject($sObject);
  64. if (!$aObject || !is_array($aObject))
  65. return false;
  66. if (empty($aObject['override_class_name']))
  67. return false;
  68. $sClass = $aObject['override_class_name'];
  69. if (!empty($aObject['override_class_file']))
  70. require_once(BX_DIRECTORY_PATH_ROOT . $aObject['override_class_file']);
  71. $o = new $sClass($aObject, $oTemplate);
  72. return ($GLOBALS['bxDolClasses']['BxDolEmbed!'.$sObject] = $o);
  73. }
  74. /**
  75. * Get object name
  76. */
  77. public function getObjectName ()
  78. {
  79. return $this->_sObject;
  80. }
  81. /**
  82. * Print HTML which will be automatically converted into embed upon page load
  83. * @param $sLink - link
  84. * @param $sTitle - title or use link for the title if omitted
  85. * @param $sMaxWidth - try to restrict max width of embed (works in supported embed providers only)
  86. */
  87. public function getLinkHTML ($sLink, $sTitle = '', $sMaxWidth = '')
  88. {
  89. // override this function in particular editor class
  90. }
  91. /**
  92. * Add css/js files which are needed for embed display and functionality.
  93. */
  94. public function addJsCss ()
  95. {
  96. // override this function in particular editor class
  97. }
  98. }
  99. /** @} */