BxDolModuleProxy.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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('module' => $this->_oProxifiedObject->getModule(), '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. public function isMethodExists($s)
  49. {
  50. return method_exists($this->_oProxifiedObject, $s);
  51. }
  52. /**
  53. * Dirty fix for pass by reference to BxTimelineTemplate::getData
  54. */
  55. public function getData(&$aEvent, $aBrowseParams = array())
  56. {
  57. return $this->_oProxifiedObject->getData($aEvent, $aBrowseParams);
  58. }
  59. /**
  60. * Dirty fix for pass by reference to BxNtfsTemplate::getPost
  61. */
  62. public function getPost(&$aEvent, $aBrowseParams = array())
  63. {
  64. return $this->_oProxifiedObject->getPost($aEvent, $aBrowseParams);
  65. }
  66. /**
  67. * Dirty fix for pass by reference to BxNtfsTemplate::getNotificationEmail
  68. */
  69. public function getNotificationEmail(&$aEvent)
  70. {
  71. return $this->_oProxifiedObject->getNotificationEmail($aEvent);
  72. }
  73. /**
  74. * Dirty fix for pass by reference to BxNtfsTemplate::getNotificationPush
  75. */
  76. public function getNotificationPush(&$aEvent)
  77. {
  78. return $this->_oProxifiedObject->getNotificationPush($aEvent);
  79. }
  80. }
  81. /** @} */