1
0

BxDolModuleProxy.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. $oModule = ('module_template' == $this->_sObjectType ? $this->_oProxifiedObject->getModule() : null);
  36. // make it possible to override the call or arguments
  37. $res = null;
  38. /**
  39. * @hooks
  40. * @hookdef hook-module_template_method_call-method_name 'module_template_method_call', '{method_name}' - hook to override a method from template class in a module
  41. * - $unit_name - equals `module_template_method_call`
  42. * - $action - method name
  43. * - $object_id - not used
  44. * - $sender_id - not used
  45. * - $extra_params - array of additional params with the following array keys:
  46. * - `module` - [object] an instance of a module, @see BxDolModule
  47. * - `args` - [array] by ref, array with method call arguments, can be overridden in hook processing
  48. * - `override_result` - [mixed] by ref, method call response, if equals to 'null', the default method will be called, can be overridden in hook processing
  49. * @hook @ref hook-module_template_method_call-method_name
  50. */
  51. bx_alert($this->_sObjectType . '_method_call', $sMethodName, 0, 0, [
  52. 'module' => $oModule,
  53. 'args' => &$aArguments,
  54. 'override_result' => &$res
  55. ]);
  56. if (null !== $res)
  57. return $res;
  58. // call original method
  59. return call_user_func_array(array($this->_oProxifiedObject, $sMethodName), $aArguments);
  60. }
  61. else {
  62. $sClass = get_class($this->_oProxifiedObject);
  63. trigger_error('Method ' . $sMethodName . ' was not found for the class ' . $sClass, E_USER_ERROR);
  64. }
  65. }
  66. public function getClassName()
  67. {
  68. return get_class($this->_oProxifiedObject);
  69. }
  70. public function isMethodExists($s)
  71. {
  72. return method_exists($this->_oProxifiedObject, $s);
  73. }
  74. /**
  75. * Dirty fix for pass by reference to BxTimelineTemplate::getData
  76. */
  77. public function getData(&$aEvent, $aBrowseParams = array())
  78. {
  79. return $this->_oProxifiedObject->getData($aEvent, $aBrowseParams);
  80. }
  81. /**
  82. * Dirty fix for pass by reference to BxNtfsTemplate::getPost
  83. */
  84. public function getPost(&$aEvent, $aBrowseParams = array())
  85. {
  86. return $this->_oProxifiedObject->getPost($aEvent, $aBrowseParams);
  87. }
  88. /**
  89. * Dirty fix for pass by reference to BxNtfsTemplate::getNotificationEmail
  90. */
  91. public function getNotificationEmail($iRecipient, &$aEvent)
  92. {
  93. return $this->_oProxifiedObject->getNotificationEmail($iRecipient, $aEvent);
  94. }
  95. /**
  96. * Dirty fix for pass by reference to BxNtfsTemplate::getNotificationPush
  97. */
  98. public function getNotificationPush($iRecipient, &$aEvent)
  99. {
  100. return $this->_oProxifiedObject->getNotificationPush($iRecipient, $aEvent);
  101. }
  102. }
  103. /** @} */