BxDolModuleProxy.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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($s, $sMethodName)) {
  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. /** @} */