function triggerEvent($category, $item_id, $event, $extra_tags = array(), $user_list = array(), $module_id = null, $omit_user_id = null) { if (!isset($module_id)) { global $xoopsModule; $module =& $xoopsModule; $module_id = !empty($xoopsModule) ? $xoopsModule->getVar('mid') : 0; } else { $module_handler = xoops_gethandler('module'); $module =& $module_handler->get($module_id); } // Get Config Array form xoops_version.php $not_config = $module->getInfo('notification'); // $event_correct = false; foreach ($not_config['event'] as $event_config) { if ($event_config['name'] == $event && $event_config['category'] == $category) { $event_correct = true; break; } } // RaiseEvent 'XoopsNotificationHandler.Trigger' ('Legacy.Notify.Trigger') // Delegate may hanldle notified event // varArgs : // 'category' [I] : Paramater $category of triggerEvent() // 'event' [I] : Paramater $event of triggerEvent() // 'itemId' [I] : Paramater $item_id of triggerEvent() // 'extraTags' [I] : Paramater $extra_tags of triggerEvent() // 'userList' [I] : Paramater $user_list of triggerEvent() // 'omitUid' [I] : Paramater $omit_user_id of triggerEvent() // 'module' [I] : Paramater $module_id of triggerEvent() , or currenr $xoopsModule // 'eventConfig' [I] : $modversion['notification'] Array , defined in xoops_version.php // 'force_return' [O] : If force return this triggerEvents method, set it True // if ($event_correct) { /* $varArgs = array('category' => $category, 'event' => $event, 'itemId' => $item_id, 'extraTags' => $extra_tags, 'module' => &$module, 'userList' => $user_list, 'omitUid' => $omit_user_id, 'eventConfig' => $not_config, 'force_return' => false, );*/ $force_return = false; $this->mTriggerPreAction->call(new XCube_Ref($category), new XCube_Ref($event), new XCube_Ref($item_id), new XCube_Ref($extra_tags), new XCube_Ref($module), new XCube_Ref($user_list), new XCube_Ref($omit_user_id), new XCube_Ref($not_config), new XCube_Ref($force_return)); $this->mTrigger->call($category, $event, $item_id, $extra_tags, new XCube_Ref($module), $user_list, $omit_user_id, $not_config, new XCube_Ref($force_return)); if ($force_return) { return; } } // Check if event is enabled $config_handler = xoops_gethandler('config'); $mod_config =& $config_handler->getConfigsByCat(0, $module->getVar('mid')); if (empty($mod_config['notification_enabled'])) { return false; } $category_info =& notificationCategoryInfo($category, $module_id); $event_info =& notificationEventInfo($category, $event, $module_id); if (!in_array(notificationGenerateConfig($category_info, $event_info, 'option_name'), $mod_config['notification_events']) && empty($event_info['invisible'])) { return false; } if (!isset($omit_user_id)) { global $xoopsUser; if (!empty($xoopsUser)) { $omit_user_id = $xoopsUser->getVar('uid'); } else { $omit_user_id = 0; } } $criteria = new CriteriaCompo(); $criteria->add(new Criteria('not_modid', (int) $module_id)); $criteria->add(new Criteria('not_category', $this->_escapeValue($category))); $criteria->add(new Criteria('not_itemid', (int) $item_id)); $criteria->add(new Criteria('not_event', $this->_escapeValue($event))); $mode_criteria = new CriteriaCompo(); $mode_criteria->add(new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDALWAYS), 'OR'); $mode_criteria->add(new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE), 'OR'); $mode_criteria->add(new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT), 'OR'); $criteria->add($mode_criteria); if (!empty($user_list)) { $user_criteria = new CriteriaCompo(); foreach ($user_list as $user) { $user_criteria->add(new Criteria('not_uid', $user), 'OR'); } $criteria->add($user_criteria); } $notifications =& $this->getObjects($criteria); if (empty($notifications)) { return; } // Add some tag substitutions here $tags = array(); if (!empty($not_config)) { if (!empty($not_config['tags_file'])) { $tags_file = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname') . '/' . $not_config['tags_file']; if (file_exists($tags_file)) { include_once $tags_file; if (!empty($not_config['tags_func'])) { $tags_func = $not_config['tags_func']; if (function_exists($tags_func)) { $tags = $tags_func($category, (int) $item_id, $event); } } } } // RMV-NEW if (!empty($not_config['lookup_file'])) { $lookup_file = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname') . '/' . $not_config['lookup_file']; if (file_exists($lookup_file)) { include_once $lookup_file; if (!empty($not_config['lookup_func'])) { $lookup_func = $not_config['lookup_func']; if (function_exists($lookup_func)) { $item_info = $lookup_func($category, (int) $item_id); } } } } } $tags['X_ITEM_NAME'] = !empty($item_info['name']) ? $item_info['name'] : '[' . _NOT_ITEMNAMENOTAVAILABLE . ']'; $tags['X_ITEM_URL'] = !empty($item_info['url']) ? $item_info['url'] : '[' . _NOT_ITEMURLNOTAVAILABLE . ']'; $tags['X_ITEM_TYPE'] = !empty($category_info['item_name']) ? $category_info['title'] : '[' . _NOT_ITEMTYPENOTAVAILABLE . ']'; $tags['X_MODULE'] = $module->getVar('name', 'n'); $tags['X_MODULE_URL'] = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/'; $tags['X_NOTIFY_CATEGORY'] = $category; $tags['X_NOTIFY_EVENT'] = $event; $template_dir = $event_info['mail_template_dir']; $template = $event_info['mail_template'] . '.tpl'; $subject = $event_info['mail_subject']; foreach ($notifications as $notification) { if (empty($omit_user_id) || $notification->getVar('not_uid') != $omit_user_id) { // user-specific tags //$tags['X_UNSUBSCRIBE_URL'] = 'TODO'; // TODO: don't show unsubscribe link if it is 'one-time' ?? $tags['X_UNSUBSCRIBE_URL'] = XOOPS_URL . '/notifications.php'; $tags = array_merge($tags, $extra_tags); $notification->notifyUser($template_dir, $template, $subject, $tags); } } }
/** * Determine whether a particular notification event is enabled. * Depends on module config options. * * @todo Check that this works correctly for comment and other * events which depend on additional config options... * * @param array $category Category info array * @param array $event Event info array * @param object $module Module * @return bool **/ function notificationEventEnabled(&$category, &$event, &$module) { $config_handler =& xoops_gethandler('config'); $mod_config = $config_handler->getConfigsByCat(0, $module->getVar('mid')); $option_name = notificationGenerateConfig($category, $event, 'option_name'); if (in_array($option_name, $mod_config['notification_events'])) { return true; } $notification_handler =& xoops_gethandler('notification'); return false; }
function xsns_main_trigger_event( $category , $item_id , $event , $extra_tags=array() , $user_list=array() , $omit_user_id=null ) { global $xoopsModule , $xoopsConfig , $mydirname , $mydirpath; $notification_handler =& xoops_gethandler('notification') ; $mid = $xoopsModule->getVar('mid') ; // language $language = empty($xoopsConfig['language']) ? 'japanese' : $xoopsConfig['language'] ; $trustdirpath = dirname(dirname(__FILE__)); if( file_exists( "$mydirpath/language/$language/mail_template/" ) ) { $mail_template_dir = "$mydirpath/language/$language/mail_template/" ; } else if( file_exists( $trustdirpath."/language/$language/mail_template/" ) ) { $mail_template_dir = $trustdirpath."/language/$language/mail_template/"; } else { $mail_template_dir = $trustdirpath."/language/japanese/mail_template/"; } // Check if event is enabled $config_handler =& xoops_gethandler('config'); $mod_config =& $config_handler->getConfigsByCat(0,$mid); if (empty($mod_config['notification_enabled'])) { return false; } $category_info =& notificationCategoryInfo ($category, $mid); $event_info =& notificationEventInfo ($category, $event, $mid); if (!in_array(notificationGenerateConfig($category_info,$event_info,'option_name'),$mod_config['notification_events']) && empty($event_info['invisible'])) { return false; } if (!isset($omit_user_id)) { global $xoopsUser; if (!empty($xoopsUser)) { $omit_user_id = $xoopsUser->getVar('uid'); } else { $omit_user_id = 0; } } $criteria = new CriteriaCompo(); $criteria->add(new Criteria('not_modid', intval($mid))); $criteria->add(new Criteria('not_category', $category)); $criteria->add(new Criteria('not_itemid', intval($item_id))); $criteria->add(new Criteria('not_event', $event)); $mode_criteria = new CriteriaCompo(); $mode_criteria->add (new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDALWAYS), 'OR'); $mode_criteria->add (new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE), 'OR'); $mode_criteria->add (new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT), 'OR'); $criteria->add($mode_criteria); if (!empty($user_list)) { $user_criteria = new CriteriaCompo(); foreach ($user_list as $user) { $user_criteria->add (new Criteria('not_uid', $user), 'OR'); } $criteria->add($user_criteria); } $notifications =& $notification_handler->getObjects($criteria); if (empty($notifications)) { return; } // Add some tag substitutions here $tags = array(); // {X_ITEM_NAME} {X_ITEM_URL} {X_ITEM_TYPE} from lookup_func are disabled $tags['X_MODULE'] = $xoopsModule->getVar('name','n'); $tags['X_MODULE_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/'; $tags['X_NOTIFY_CATEGORY'] = $category; $tags['X_NOTIFY_EVENT'] = $event; $template = $event_info['mail_template'] . '.tpl'; $subject = $event_info['mail_subject']; foreach ($notifications as $notification) { if (empty($omit_user_id) || $notification->getVar('not_uid') != $omit_user_id) { $tags['X_UNSUBSCRIBE_URL'] = XOOPS_URL . '/notifications.php'; $tags = array_merge($tags, $extra_tags); $notification->notifyUser($mail_template_dir, $template, $subject, $tags); } } }
function triggerEvent($category, $item_id, $event, $extra_tags = array(), $user_list = array(), $module_id = null, $omit_user_id = null) { if (!isset($module_id)) { global $xoopsModule; $module =& $xoopsModule; $module_id = !empty($xoopsModule) ? $xoopsModule->getVar('mid') : 0; } else { $module_handler =& xoops_gethandler('module'); $module =& $module_handler->get($module_id); } // Check if event is enabled $config_handler =& xoops_gethandler('config'); $mod_config =& $config_handler->getConfigsByCat(0, $module->getVar('mid')); if (empty($mod_config['notification_enabled'])) { return false; } $category_info =& notificationCategoryInfo($category, $module_id); $event_info =& notificationEventInfo($category, $event, $module_id); if (!in_array(notificationGenerateConfig($category_info, $event_info, 'option_name'), $mod_config['notification_events']) && empty($event_info['invisible'])) { return false; } if (!isset($omit_user_id)) { global $xoopsUser; if (!empty($xoopsUser)) { $omit_user_id = $xoopsUser->getVar('uid'); } else { $omit_user_id = 0; } } $criteria = new CriteriaCompo(); $criteria->add(new Criteria('not_modid', intval($module_id))); $criteria->add(new Criteria('not_category', $category)); $criteria->add(new Criteria('not_itemid', intval($item_id))); $criteria->add(new Criteria('not_event', $event)); $mode_criteria = new CriteriaCompo(); $mode_criteria->add(new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDALWAYS), 'OR'); $mode_criteria->add(new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE), 'OR'); $mode_criteria->add(new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT), 'OR'); $criteria->add($mode_criteria); if (!empty($user_list)) { $user_criteria = new CriteriaCompo(); foreach ($user_list as $user) { $user_criteria->add(new Criteria('not_uid', $user), 'OR'); } $criteria->add($user_criteria); } $notifications =& $this->getObjects($criteria); if (empty($notifications)) { return; } // Add some tag substitutions here $not_config = $module->getInfo('notification'); $tags = array(); if (!empty($not_config)) { if (!empty($not_config['tags_file'])) { $tags_file = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname') . '/' . $not_config['tags_file']; if (file_exists($tags_file)) { include_once $tags_file; if (!empty($not_config['tags_func'])) { $tags_func = $not_config['tags_func']; if (function_exists($tags_func)) { $tags = $tags_func($category, intval($item_id), $event); } } } } // RMV-NEW if (!empty($not_config['lookup_file'])) { $lookup_file = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname') . '/' . $not_config['lookup_file']; if (file_exists($lookup_file)) { include_once $lookup_file; if (!empty($not_config['lookup_func'])) { $lookup_func = $not_config['lookup_func']; if (function_exists($lookup_func)) { $item_info = $lookup_func($category, intval($item_id)); } } } } } $tags['X_ITEM_NAME'] = !empty($item_info['name']) ? $item_info['name'] : '[' . _NOT_ITEMNAMENOTAVAILABLE . ']'; $tags['X_ITEM_URL'] = !empty($item_info['url']) ? $item_info['url'] : '[' . _NOT_ITEMURLNOTAVAILABLE . ']'; $tags['X_ITEM_TYPE'] = !empty($category_info['item_name']) ? $category_info['title'] : '[' . _NOT_ITEMTYPENOTAVAILABLE . ']'; $tags['X_MODULE'] = $module->getVar('name'); $tags['X_MODULE_URL'] = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/'; $tags['X_NOTIFY_CATEGORY'] = $category; $tags['X_NOTIFY_EVENT'] = $event; $template_dir = $event_info['mail_template_dir']; $template = $event_info['mail_template'] . '.tpl'; $subject = $event_info['mail_subject']; foreach ($notifications as $notification) { if (empty($omit_user_id) || $notification->getVar('not_uid') != $omit_user_id) { // user-specific tags //$tags['X_UNSUBSCRIBE_URL'] = 'TODO'; // TODO: don't show unsubscribe link if it is 'one-time' ?? $tags['X_UNSUBSCRIBE_URL'] = XOOPS_URL . '/notifications.php'; $tags = array_merge($tags, $extra_tags); $notification->notifyUser($template_dir, $template, $subject, $tags); } } }
function triggerEvent($mydirname, $mytrustdirname, $category, $item_id, $event, $extra_tags = array(), $user_list = array(), $omit_user_id = null) { $module_hanlder =& xoops_gethandler('module'); $module =& $module_hanlder->getByDirname($mydirname); $notification_handler =& xoops_gethandler('notification'); $mail_template_dir = $this->getMailTemplateDir($mydirname, $mytrustdirname); // calling a delegate before if (class_exists('XCube_DelegateUtils')) { $force_return = false; XCube_DelegateUtils::raiseEvent('D3NotificationHandler.Trigger', new XCube_Ref($category), new XCube_Ref($event), new XCube_Ref($item_id), new XCube_Ref($extra_tags), new XCube_Ref($module), new XCube_Ref($user_list), new XCube_Ref($omit_user_id), $module->getInfo('notification'), new XCube_Ref($force_return), new XCube_Ref($mail_template_dir), $mydirname, $mytrustdirname); if ($force_return) { return; } } $mid = $module->getVar('mid'); // Check if event is enabled $config_handler =& xoops_gethandler('config'); $mod_config =& $config_handler->getConfigsByCat(0, $mid); if (empty($mod_config['notification_enabled'])) { return false; } $category_info =& notificationCategoryInfo($category, $mid); $event_info =& notificationEventInfo($category, $event, $mid); if (!in_array(notificationGenerateConfig($category_info, $event_info, 'option_name'), $mod_config['notification_events']) && empty($event_info['invisible'])) { return false; } if (!isset($omit_user_id)) { global $xoopsUser; if (!empty($xoopsUser)) { $omit_user_id = $xoopsUser->getVar('uid'); } else { $omit_user_id = 0; } } $criteria = new CriteriaCompo(); $criteria->add(new Criteria('not_modid', intval($mid))); $criteria->add(new Criteria('not_category', $category)); $criteria->add(new Criteria('not_itemid', intval($item_id))); $criteria->add(new Criteria('not_event', $event)); $mode_criteria = new CriteriaCompo(); $mode_criteria->add(new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDALWAYS), 'OR'); $mode_criteria->add(new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE), 'OR'); $mode_criteria->add(new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT), 'OR'); $criteria->add($mode_criteria); if (!empty($user_list)) { $user_criteria = new CriteriaCompo(); foreach ($user_list as $user) { $user_criteria->add(new Criteria('not_uid', $user), 'OR'); } $criteria->add($user_criteria); } $notifications =& $notification_handler->getObjects($criteria); if (empty($notifications)) { return; } // Add some tag substitutions here $tags = array(); // {X_ITEM_NAME} {X_ITEM_URL} {X_ITEM_TYPE} from lookup_func are disabled $tags['X_MODULE'] = $module->getVar('name', 'n'); $tags['X_MODULE_URL'] = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/'; $tags['X_NOTIFY_CATEGORY'] = $category; $tags['X_NOTIFY_EVENT'] = $event; $template = $event_info['mail_template'] . '.tpl'; $subject = $event_info['mail_subject']; foreach ($notifications as $notification) { if (empty($omit_user_id) || $notification->getVar('not_uid') != $omit_user_id) { // user-specific tags //$tags['X_UNSUBSCRIBE_URL'] = 'TODO'; // TODO: don't show unsubscribe link if it is 'one-time' ?? $tags['X_UNSUBSCRIBE_URL'] = XOOPS_URL . '/notifications.php'; $tags = array_merge($tags, $extra_tags); $notification->notifyUser($mail_template_dir, $template, $subject, $tags); } } }
function system_notification($page, $category, $item_id, $event, $extra_tags = array(), $user_list = array(), $omit_user_id = null) { //global $xoopsModule , $xoopsConfig , $mydirname , $mydirpath , $mytrustdirname , $mytrustdirpath ; // RMV-NOTIFY include_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; include_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; $config_handler =& xoops_gethandler('config'); $xoopsConfig =& $config_handler->getConfigsByCat(XOOPS_CONF); $mid = $this->root->module['mid']; // Check if event is enabled $config_handler =& xoops_gethandler('config'); $mod_config =& $config_handler->getConfigsByCat(0, $mid); if (empty($mod_config['notification_enabled'])) { return false; } $category_info =& notificationCategoryInfo($category, $mid); $event_info =& notificationEventInfo($category, $event, $mid); if (!in_array(notificationGenerateConfig($category_info, $event_info, 'option_name'), $mod_config['notification_events']) && empty($event_info['invisible'])) { return false; } if (is_null($omit_user_id)) { $omit_user_id = $this->root->userinfo['uid']; } $criteria = new CriteriaCompo(); $criteria->add(new Criteria('not_modid', intval($mid))); $criteria->add(new Criteria('not_category', $category)); $criteria->add(new Criteria('not_itemid', intval($item_id))); $criteria->add(new Criteria('not_event', $event)); $mode_criteria = new CriteriaCompo(); $mode_criteria->add(new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDALWAYS), 'OR'); $mode_criteria->add(new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE), 'OR'); $mode_criteria->add(new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT), 'OR'); $criteria->add($mode_criteria); if (!empty($user_list)) { $user_criteria = new CriteriaCompo(); foreach ($user_list as $user) { $user_criteria->add(new Criteria('not_uid', $user), 'OR'); } $criteria->add($user_criteria); } $notification_handler =& xoops_gethandler('notification'); $notifications =& $notification_handler->getObjects($criteria); if (empty($notifications)) { return; } // language file $language = empty($xoopsConfig['language']) ? 'english' : $xoopsConfig['language']; if (is_dir($this->root->mydirpath . "/language/{$language}/mail_template")) { // user customized language file $mail_template_dir = $this->root->mydirpath . "/language/{$language}/mail_template/"; } else { if (is_dir($this->root->mytrustdirpath . "/language/{$language}/mail_template")) { // default language file $mail_template_dir = $this->root->mytrustdirpath . "/language/{$language}/mail_template/"; } else { // fallback english $mail_template_dir = $this->root->mytrustdirpath . "/language/english/mail_template/"; } } // Add some tag substitutions here $tags = array(); // {X_ITEM_NAME} {X_ITEM_URL} {X_ITEM_TYPE} from lookup_func are disabled $tags['X_MODULE'] = $this->root->module['name']; $tags['X_MODULE_URL'] = $this->root->script; $tags['X_NOTIFY_CATEGORY'] = $category; $tags['X_NOTIFY_EVENT'] = $event; $template = $event_info['mail_template'] . '.tpl'; $subject = $event_info['mail_subject']; foreach ($notifications as $notification) { if (empty($omit_user_id) || $notification->getVar('not_uid') != $omit_user_id) { // 表示権限チェック if ($this->check_readable_page($page, false, false, $notification->getVar('not_uid'))) { // user-specific tags //$tags['X_UNSUBSCRIBE_URL'] = 'TODO'; // TODO: don't show unsubscribe link if it is 'one-time' ?? $tags['X_UNSUBSCRIBE_URL'] = XOOPS_URL . '/notifications.php'; $tags = array_merge($tags, $extra_tags); $notification->notifyUser($mail_template_dir, $template, $subject, $tags); } } } }