/** * Load the module info for this module * * @param string $dirname Module directory * @param bool $verbose Give an error on fail? * * @return bool * * @todo the $modVersions array should be built once when modules are installed/updated and then cached */ public function loadInfo($dirname, $verbose = true) { static $modVersions; if (empty($dirname)) { return false; } $dirname = basename($dirname); if (isset($modVersions[$dirname])) { $this->modinfo = $modVersions[$dirname]; return true; } $xoops = xoops::getInstance(); $dirname = basename($dirname); $xoops->loadLanguage('modinfo', $dirname); $xoops->loadLocale($dirname); if (!XoopsLoad::fileExists($file = $xoops->path('modules/' . $dirname . '/xoops_version.php'))) { if (false != $verbose) { echo "Module File for {$dirname} Not Found!"; } return false; } $modversion = array(); include $file; $modVersions[$dirname] = $modversion; $this->modinfo = $modVersions[$dirname]; return true; }
/** * triggerEvent * * @param int $category notification category * @param int $item_id ID of the item * @param int $event notification event * @param array $extra_tags array of substitutions for template * @param array $user_list users to notify * @param int $module_id module * @param int $omit_user_id users to not notify * * @return bool */ public function triggerEvent($category, $item_id, $event, $extra_tags = array(), $user_list = array(), $module_id = null, $omit_user_id = null) { $xoops = xoops::getInstance(); $helper = Notifications::getInstance(); if (!isset($module_id)) { $module = $xoops->module; $module_id = $xoops->isModule() ? $xoops->module->getVar('mid') : 0; } else { $module = $xoops->getHandlerModule()->get($module_id); } // Check if event is enabled $mod_config = $xoops->getHandlerConfig()->getConfigsByModule($module->getVar('mid')); if (empty($mod_config['notifications_enabled'])) { return false; } $category_info = $helper->getCategory($category, $module->getVar('dirname')); $event_info = $helper->getEvent($category, $event, $module->getVar('dirname')); if (!in_array($helper->generateConfig($category_info, $event_info, 'option_name'), $mod_config['notification_events']) && empty($event_info['invisible'])) { return false; } if (!isset($omit_user_id)) { if ($xoops->isUser()) { $omit_user_id = $xoops->user->getVar('uid'); } else { $omit_user_id = 0; } } $criteria = new CriteriaCompo(); $criteria->add(new Criteria('modid', (int) $module_id)); $criteria->add(new Criteria('category', $category)); $criteria->add(new Criteria('itemid', (int) $item_id)); $criteria->add(new Criteria('event', $event)); $mode_criteria = new CriteriaCompo(); $mode_criteria->add(new Criteria('mode', NOTIFICATIONS_MODE_SENDALWAYS), 'OR'); $mode_criteria->add(new Criteria('mode', NOTIFICATIONS_MODE_SENDONCETHENDELETE), 'OR'); $mode_criteria->add(new Criteria('mode', NOTIFICATIONS_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('uid', (int) $user), 'OR'); } $criteria->add($user_criteria); } $notifications = $this->getObjectsArray($criteria); if (empty($notifications)) { return false; } $item_info = $helper->getEvent($category, $item_id, $module->getVar('dirname')); // Add some tag substitutions here $tags = $helper->getTags($category, $item_id, $event, $module->getVar('dirname')); $tags['X_ITEM_NAME'] = !empty($item_info['name']) ? $item_info['name'] : '[' . _MD_NOTIFICATIONS_ITEMNAMENOTAVAILABLE . ']'; $tags['X_ITEM_URL'] = !empty($item_info['url']) ? $item_info['url'] : '[' . _MD_NOTIFICATIONS_ITEMURLNOTAVAILABLE . ']'; $tags['X_ITEM_TYPE'] = !empty($category_info['item_name']) ? $category_info['title'] : '[' . _MD_NOTIFICATIONS_ITEMTYPENOTAVAILABLE . ']'; $tags['X_MODULE'] = $module->getVar('name'); $tags['X_MODULE_URL'] = \XoopsBaseConfig::get('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) { /* @var $notification NotificationsNotification */ if (empty($omit_user_id) || $notification->getVar('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'] = $helper->url('index.php'); $tags = array_merge($tags, $extra_tags); $notification->notifyUser($template_dir, $template, $subject, $tags); } } return true; }
/** * Is the user admin ? * * This method will return true if this user has admin rights for the specified module.<br /> * - If you don't specify any module ID, the current module will be checked.<br /> * - If you set the module_id to -1, it will return true if the user has admin rights for at least one module * * @param int $module_id check if user is admin of this module * @return bool is the user admin of that module? */ public function isAdmin($module_id = null) { $xoops = xoops::getInstance(); if (is_null($module_id)) { $module_id = $xoops->isModule() ? $xoops->module->getVar('mid', 'n') : 1; } elseif ((int) $module_id < 1) { $module_id = 0; } $moduleperm_handler = $xoops->getHandlerGroupperm(); return $moduleperm_handler->checkRight('module_admin', $module_id, $this->getGroups()); }