message.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. global $app;
  3. helper::import($app->getModulePath('', 'message') . 'model.php');
  4. class extmessageModel extends messageModel
  5. {
  6. public function send($objectType, $objectID, $actionType, $actionID, $actor = '', $extra = '')
  7. {
  8. $this->loadExtension('xuanxuan')->send($objectType, $objectID, $actionType, $actionID, $actor, $extra);
  9. if(commonModel::isTutorialMode()) return;
  10. $objectType = strtolower($objectType);
  11. $messageSetting = $this->config->message->setting;
  12. if(is_string($messageSetting)) $messageSetting = json_decode($messageSetting, true);
  13. /* 如果是业需和用需,则使用它们的发信配置。*/
  14. if($objectType == 'story')
  15. {
  16. $story = $this->loadModel('story')->fetchByID($objectID);
  17. if($story) $objectType = $story->type;
  18. if($story && $story->status == 'draft') return;
  19. }
  20. if(isset($messageSetting['mail']))
  21. {
  22. $actions = $messageSetting['mail']['setting'];
  23. if(isset($actions[$objectType]) && in_array($actionType, $actions[$objectType]))
  24. {
  25. /* If it is an api call, get the request method set by the user. */
  26. global $config;
  27. $requestType = $config->requestType;
  28. if(defined('RUN_MODE') && RUN_MODE == 'api')
  29. {
  30. $configRoot = $this->app->getConfigRoot();
  31. include file_exists($configRoot . 'my.php') ? $configRoot . 'my.php' : $configRoot . 'config.php';
  32. }
  33. if($objectType == 'feedback' || $objectType == 'ticket')
  34. {
  35. $this->loadModel($objectType)->sendmail($objectID, $actionID);
  36. }
  37. else
  38. {
  39. $this->loadModel('mail')->sendmail($objectID, $actionID);
  40. }
  41. if(defined('RUN_MODE') && RUN_MODE == 'api') $config->requestType = $requestType;
  42. }
  43. }
  44. if(isset($messageSetting['webhook']))
  45. {
  46. $actions = $messageSetting['webhook']['setting'];
  47. if(isset($actions[$objectType]) && in_array($actionType, $actions[$objectType])) $this->loadModel('webhook')->send($objectType, $objectID, $actionType, $actionID, $actor);
  48. }
  49. if(isset($messageSetting['message']))
  50. {
  51. $isBuiltinMethod = true;
  52. if($this->config->edition != 'open')
  53. {
  54. $groupID = $this->loadModel('workflowgroup')->getGroupIDByDataID($objectType, $objectID);
  55. $method = $this->loadModel('workflowaction')->getByModuleAndAction($objectType, $this->app->rawMethod, $groupID);
  56. if($method && !$method->buildin) $isBuiltinMethod = false;
  57. }
  58. $actions = $messageSetting['message']['setting'];
  59. if($isBuiltinMethod && isset($actions[$objectType]) && in_array($actionType, $actions[$objectType])) $this->saveNotice($objectType, $objectID, $actionType, $actionID, $actor);
  60. }
  61. }
  62. //**//
  63. }