BxDolModuleProxy.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. 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 BxMessengerTemplate::getTalkBlock
  68. */
  69. public function getTalkBlock($iProfileId, $iLotId = BX_IM_EMPTY, $iJotId = BX_IM_EMPTY, $iType = BX_IM_TYPE_PUBLIC, $bShowMessanger = false, &$sReturnTitle = '')
  70. {
  71. return $this->_oProxifiedObject->getTalkBlock($iProfileId, $iLotId, $iJotId, $iType, $bShowMessanger, $sReturnTitle);
  72. }
  73. }
  74. /** @} */