BxDolModuleProxy.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. * Proxy class for module classes, now only module template class is proxied.
  11. * It's possible to override any module template method call by making a response
  12. * for 'module_template_method_call' alert.
  13. */
  14. class BxDolModuleProxy
  15. {
  16. private $_oProxifiedObject;
  17. private $_sObjectType;
  18. function __construct($sObjectType, $oProxifiedObject)
  19. {
  20. $this->_sObjectType = $sObjectType;
  21. $this->_oProxifiedObject = $oProxifiedObject;
  22. }
  23. public function __call($sMethodName, $aArguments)
  24. {
  25. if (is_callable(array($this->_oProxifiedObject, $sMethodName))) {
  26. // check if we need to include css&js files
  27. if ('module_template' == $this->_sObjectType && !empty($this->_oProxifiedObject->aMethodsToCallAddJsCss)) {
  28. foreach ($this->_oProxifiedObject->aMethodsToCallAddJsCss as $s) {
  29. if (0 === strpos($sMethodName, $s)) {
  30. $this->_oProxifiedObject->addCssJs();
  31. break;
  32. }
  33. }
  34. }
  35. // make it possible to override the call or arguments
  36. $res = null;
  37. bx_alert($this->_sObjectType . '_method_call', $sMethodName, 0, 0, array('args' => &$aArguments, 'override_result' => &$res));
  38. if (null !== $res)
  39. return $res;
  40. // call original method
  41. return call_user_func_array(array($this->_oProxifiedObject, $sMethodName), $aArguments);
  42. }
  43. else {
  44. $sClass = get_class($this->_oProxifiedObject);
  45. trigger_error('Method ' . $sMethodName . ' was not found for the class ' . $sClass, E_USER_ERROR);
  46. }
  47. }
  48. /**
  49. * Dirty fix for pass by reference to BxTimelineTemplate::getData
  50. */
  51. public function getData(&$aEvent, $aBrowseParams = array())
  52. {
  53. return $this->_oProxifiedObject->getData($aEvent, $aBrowseParams);
  54. }
  55. /**
  56. * Dirty fix for pass by reference to BxNtfsTemplate::getPost
  57. */
  58. public function getPost(&$aEvent, $aBrowseParams = array())
  59. {
  60. return $this->_oProxifiedObject->getPost($aEvent, $aBrowseParams);
  61. }
  62. /**
  63. * Dirty fix for pass by reference to BxMessengerTemplate::getTalkBlock
  64. */
  65. public function getTalkBlock($iProfileId, $iLotId = BX_IM_EMPTY, $iJotId = BX_IM_EMPTY, $iType = BX_IM_TYPE_PUBLIC, $bShowMessanger = false, &$sReturnTitle = '')
  66. {
  67. return $this->_oProxifiedObject->getTalkBlock($iProfileId, $iLotId, $iJotId, $iType, $bShowMessanger, $sReturnTitle);
  68. }
  69. }
  70. /** @} */