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); } } }
function xoops_module_install($dirname) { global $xoopsUser, $xoopsConfig; $dirname = trim($dirname); $db =& Database::getInstance(); $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish'); $module_handler =& xoops_gethandler('module'); if ($module_handler->getCount(new Criteria('dirname', $dirname)) == 0) { $module =& $module_handler->create(); $module->loadInfoAsVar($dirname); $module->setVar('weight', 1); $error = false; $errs = array(); $sqlfile =& $module->getInfo('sqlfile'); $msgs = array(); $msgs[] = '<h4 style="text-align:left;margin-bottom: 0px;border-bottom: dashed 1px #000000;">Installing ' . $module->getInfo('name') . '</h4>'; if ($module->getInfo('image') != false && trim($module->getInfo('image')) != '') { $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" />'; } $msgs[] = '<b>Version:</b> ' . $module->getInfo('version'); if ($module->getInfo('author') != false && trim($module->getInfo('author')) != '') { $msgs[] = '<b>Author:</b> ' . trim($module->getInfo('author')); } $msgs[] = ''; $errs[] = '<h4 style="text-align:left;margin-bottom: 0px;border-bottom: dashed 1px #000000;">Installing ' . $module->getInfo('name') . '</h4>'; if ($sqlfile != false && is_array($sqlfile)) { $sql_file_path = XOOPS_ROOT_PATH . "/modules/" . $dirname . "/" . $sqlfile[XOOPS_DB_TYPE]; if (!file_exists($sql_file_path)) { $errs[] = "SQL file not found at <b>{$sql_file_path}</b>"; $error = true; } else { $msgs[] = "SQL file found at <b>{$sql_file_path}</b>.<br /> Creating tables..."; include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php'; $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path)); $sql_query = trim($sql_query); SqlUtility::splitMySqlFile($pieces, $sql_query); $created_tables = array(); foreach ($pieces as $piece) { // [0] contains the prefixed query // [4] contains unprefixed table name $prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix()); if (!$prefixed_query) { $errs[] = "<b>{$piece}</b> is not a valid SQL!"; $error = true; break; } // check if the table name is reserved if (!in_array($prefixed_query[4], $reservedTables)) { // not reserved, so try to create one if (!$db->query($prefixed_query[0])) { $errs[] = $db->error(); $error = true; break; } else { if (!in_array($prefixed_query[4], $created_tables)) { $msgs[] = ' Table <b>' . $db->prefix($prefixed_query[4]) . '</b> created.'; $created_tables[] = $prefixed_query[4]; } else { $msgs[] = ' Data inserted to table <b>' . $db->prefix($prefixed_query[4]) . '</b>.'; } } } else { // the table name is reserved, so halt the installation $errs[] = '<b>' . $prefixed_query[4] . "</b> is a reserved table!"; $error = true; break; } } // if there was an error, delete the tables created so far, so the next installation will not fail if ($error == true) { foreach ($created_tables as $ct) { //echo $ct; $db->query("DROP TABLE " . $db->prefix($ct)); } } } } // if no error, save the module info and blocks info associated with it if ($error == false) { if (!$module_handler->insert($module)) { $errs[] = 'Could not insert <b>' . $module->getVar('name') . '</b> to database.'; foreach ($created_tables as $ct) { $db->query("DROP TABLE " . $db->prefix($ct)); } $ret = "<p>" . sprintf(_MD_AM_FAILINS, "<b>" . $module->name() . "</b>") . " " . _MD_AM_ERRORSC . "<br />"; foreach ($errs as $err) { $ret .= " - " . $err . "<br />"; } $ret .= "</p>"; unset($module); unset($created_tables); unset($errs); unset($msgs); return $ret; } else { $newmid = $module->getVar('mid'); unset($created_tables); $msgs[] = 'Module data inserted successfully. Module ID: <b>' . $newmid . '</b>'; $tplfile_handler =& xoops_gethandler('tplfile'); $templates = $module->getInfo('templates'); if ($templates != false) { $msgs[] = 'Adding templates...'; foreach ($templates as $tpl) { $tplfile =& $tplfile_handler->create(); $tpldata =& xoops_module_gettemplate($dirname, $tpl['file']); $tplfile->setVar('tpl_source', $tpldata, true); $tplfile->setVar('tpl_refid', $newmid); $tplfile->setVar('tpl_tplset', 'default'); $tplfile->setVar('tpl_file', $tpl['file']); $tplfile->setVar('tpl_desc', $tpl['description'], true); $tplfile->setVar('tpl_module', $dirname); $tplfile->setVar('tpl_lastmodified', time()); $tplfile->setVar('tpl_lastimported', 0); $tplfile->setVar('tpl_type', 'module'); if (!$tplfile_handler->insert($tplfile)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not insert template <b>' . $tpl['file'] . '</b> to the database.</span>'; } else { $newtplid = $tplfile->getVar('tpl_id'); $msgs[] = ' Template <b>' . $tpl['file'] . '</b> added to the database. (ID: <b>' . $newtplid . '</b>)'; // generate compiled file include_once XOOPS_ROOT_PATH . '/class/template.php'; if (!xoops_template_touch($newtplid)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Failed compiling template <b>' . $tpl['file'] . '</b>.</span>'; } else { $msgs[] = ' Template <b>' . $tpl['file'] . '</b> compiled.</span>'; } } unset($tpldata); } } include_once XOOPS_ROOT_PATH . '/class/template.php'; xoops_template_clear_module_cache($newmid); $blocks = $module->getInfo('blocks'); if ($blocks != false) { $msgs[] = 'Adding blocks...'; foreach ($blocks as $blockkey => $block) { // break the loop if missing block config if (!isset($block['file']) || !isset($block['show_func'])) { break; } $options = ''; if (!empty($block['options'])) { $options = trim($block['options']); } $newbid = $db->genId($db->prefix('newblocks') . '_bid_seq'); $edit_func = isset($block['edit_func']) ? trim($block['edit_func']) : ''; $template = ''; if (isset($block['template']) && trim($block['template']) != '') { $content =& xoops_module_gettemplate($dirname, $block['template'], true); } if (!isset($content)) { $content = ''; } else { $template = trim($block['template']); } $block_name = addslashes(trim($block['name'])); $sql = "INSERT INTO " . $db->prefix("newblocks") . " (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, c_type, isactive, dirname, func_file, show_func, edit_func, template, bcachetime, last_modified) VALUES ({$newbid}, {$newmid}, " . intval($blockkey) . ", '{$options}', '" . $block_name . "','" . $block_name . "', '', 0, 0, 0, 'M', 'H', 1, '" . addslashes($dirname) . "', '" . addslashes(trim($block['file'])) . "', '" . addslashes(trim($block['show_func'])) . "', '" . addslashes($edit_func) . "', '" . $template . "', 0, " . time() . ")"; if (!$db->query($sql)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not add block <b>' . $block['name'] . '</b> to the database! Database error: <b>' . $db->error() . '</b></span>'; } else { if (empty($newbid)) { $newbid = $db->getInsertId(); } $msgs[] = ' Block <b>' . $block['name'] . '</b> added. Block ID: <b>' . $newbid . '</b>'; $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)'; $db->query($sql); if ($template != '') { $tplfile =& $tplfile_handler->create(); $tplfile->setVar('tpl_refid', $newbid); $tplfile->setVar('tpl_source', $content, true); $tplfile->setVar('tpl_tplset', 'default'); $tplfile->setVar('tpl_file', $block['template']); $tplfile->setVar('tpl_module', $dirname); $tplfile->setVar('tpl_type', 'block'); $tplfile->setVar('tpl_desc', $block['description'], true); $tplfile->setVar('tpl_lastimported', 0); $tplfile->setVar('tpl_lastmodified', time()); if (!$tplfile_handler->insert($tplfile)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not insert template <b>' . $block['template'] . '</b> to the database.</span>'; } else { $newtplid = $tplfile->getVar('tpl_id'); $msgs[] = ' Template <b>' . $block['template'] . '</b> added to the database. (ID: <b>' . $newtplid . '</b>)'; // generate compiled file include_once XOOPS_ROOT_PATH . '/class/template.php'; if (!xoops_template_touch($newtplid)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Failed compiling template <b>' . $block['template'] . '</b>.</span>'; } else { $msgs[] = ' Template <b>' . $block['template'] . '</b> compiled.</span>'; } } } } unset($content); } unset($blocks); } $configs = $module->getInfo('config'); if ($configs != false) { if ($module->getVar('hascomments') != 0) { include_once XOOPS_ROOT_PATH . '/include/comment_constants.php'; array_push($configs, array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN))); array_push($configs, array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0)); } } else { if ($module->getVar('hascomments') != 0) { $configs = array(); include_once XOOPS_ROOT_PATH . '/include/comment_constants.php'; $configs[] = array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN)); $configs[] = array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0); } } // RMV-NOTIFY if ($module->getVar('hasnotification') != 0) { if (empty($configs)) { $configs = array(); } // Main notification options include_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; include_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; $options = array(); $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE; $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK; $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE; $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH; //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1); $configs[] = array('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options' => $options); // Event-specific notification options // FIXME: doesn't work when update module... can't read back the array of options properly... " changing to " $options = array(); $categories =& notificationCategoryInfo('', $module->getVar('mid')); foreach ($categories as $category) { $events =& notificationEvents($category['name'], false, $module->getVar('mid')); foreach ($events as $event) { if (!empty($event['invisible'])) { continue; } $option_name = $category['title'] . ' : ' . $event['title']; $option_value = $category['name'] . '-' . $event['name']; $options[$option_name] = $option_value; } } $configs[] = array('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($options), 'options' => $options); } if ($configs != false) { $msgs[] = 'Adding module config data...'; $config_handler =& xoops_gethandler('config'); $order = 0; foreach ($configs as $config) { $confobj =& $config_handler->createConfig(); $confobj->setVar('conf_modid', $newmid); $confobj->setVar('conf_catid', 0); $confobj->setVar('conf_name', $config['name']); $confobj->setVar('conf_title', $config['title'], true); $confobj->setVar('conf_desc', $config['description'], true); $confobj->setVar('conf_formtype', $config['formtype']); $confobj->setVar('conf_valuetype', $config['valuetype']); $confobj->setConfValueForInput($config['default'], true); //$confobj->setVar('conf_value', $config['default'], true); $confobj->setVar('conf_order', $order); $confop_msgs = ''; if (isset($config['options']) && is_array($config['options'])) { foreach ($config['options'] as $key => $value) { $confop =& $config_handler->createConfigOption(); $confop->setVar('confop_name', $key, true); $confop->setVar('confop_value', $value, true); $confobj->setConfOptions($confop); $confop_msgs .= '<br /> Config option added. Name: <b>' . $key . '</b> Value: <b>' . $value . '</b>'; unset($confop); } } $order++; if ($config_handler->insertConfig($confobj) != false) { $msgs[] = ' Config <b>' . $config['name'] . '</b> added to the database.' . $confop_msgs; } else { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not insert config <b>' . $config['name'] . '</b> to the database.</span>'; } unset($confobj); } unset($configs); } } $groups = $xoopsUser->getGroups(); // retrieve all block ids for this module $blocks =& XoopsBlock::getByModule($newmid, false); $msgs[] = 'Setting group rights...'; $gperm_handler =& xoops_gethandler('groupperm'); foreach ($groups as $mygroup) { if ($gperm_handler->checkRight('module_admin', 0, $mygroup)) { $mperm =& $gperm_handler->create(); $mperm->setVar('gperm_groupid', $mygroup); $mperm->setVar('gperm_itemid', $newmid); $mperm->setVar('gperm_name', 'module_admin'); $mperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($mperm)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not add admin access right for Group ID <b>' . $mygroup . '</b></span>'; } else { $msgs[] = ' Added admin access right for Group ID <b>' . $mygroup . '</b>'; } unset($mperm); } $mperm =& $gperm_handler->create(); $mperm->setVar('gperm_groupid', $mygroup); $mperm->setVar('gperm_itemid', $newmid); $mperm->setVar('gperm_name', 'module_read'); $mperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($mperm)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not add user access right for Group ID: <b>' . $mygroup . '</b></span>'; } else { $msgs[] = ' Added user access right for Group ID: <b>' . $mygroup . '</b>'; } unset($mperm); foreach ($blocks as $blc) { $bperm =& $gperm_handler->create(); $bperm->setVar('gperm_groupid', $mygroup); $bperm->setVar('gperm_itemid', $blc); $bperm->setVar('gperm_name', 'block_read'); $bperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($bperm)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not add block access right. Block ID: <b>' . $blc . '</b> Group ID: <b>' . $mygroup . '</b></span>'; } else { $msgs[] = ' Added block access right. Block ID: <b>' . $blc . '</b> Group ID: <b>' . $mygroup . '</b>'; } unset($bperm); } } unset($blocks); unset($groups); // execute module specific install script if any $install_script = $module->getInfo('onInstall'); if (false != $install_script && trim($install_script) != '') { include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($install_script); if (function_exists('xoops_module_install_' . $dirname)) { $func = 'xoops_module_install_' . $dirname; if (!$func($module)) { $msgs[] = 'Failed to execute ' . $func; } else { $msgs[] = '<b>' . $func . '</b> executed successfully.'; } } } $ret = '<p><code>'; foreach ($msgs as $m) { $ret .= $m . '<br />'; } unset($msgs); unset($errs); $ret .= '</code><br />' . sprintf(_MD_AM_OKINS, "<b>" . $module->getVar('name') . "</b>") . '</p>'; unset($module); return $ret; } else { $ret = '<p>'; foreach ($errs as $er) { $ret .= ' ' . $er . '<br />'; } unset($msgs); unset($errs); $ret .= '<br />' . sprintf(_MD_AM_FAILINS, '<b>' . $dirname . '</b>') . ' ' . _MD_AM_ERRORSC . '</p>'; return $ret; } } else { return "<p>" . sprintf(_MD_AM_FAILINS, "<b>" . $dirname . "</b>") . " " . _MD_AM_ERRORSC . "<br /> " . sprintf(_MD_AM_ALEXISTS, $dirname) . "</p>"; } }
function _loadNotificationPreferenceInfomations(&$modversion, &$collection) { if (isset($modversion['hasNotification']) && $modversion['hasNotification'] == true) { require_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; require_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; $t_options = array(); $t_options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE; $t_options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK; $t_options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE; $t_options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH; $notifyEnable = array('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options' => $t_options); $info =& $this->_createPreferenceInformation($notifyEnable); $collection->add($info); unset($info); // // FIXME: doesn't work when update module... can't read back the // array of options properly... " changing to " // unset($t_options); // // Get the module object to get mid. // $handler =& xoops_gethandler('module'); $module =& $handler->getByDirname($this->_mDirname); $t_options = array(); $t_categoryArr =& notificationCategoryInfo('', $module->get('mid')); foreach ($t_categoryArr as $t_category) { $t_eventArr =& notificationEvents($t_category['name'], false, $module->get('mid')); foreach ($t_eventArr as $t_event) { if (!empty($t_event['invisible'])) { continue; } $t_optionName = $t_category['title'] . ' : ' . $t_event['title']; $t_options[$t_optionName] = $t_category['name'] . '-' . $t_event['name']; } } $notifyEvents = array('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($t_options), 'options' => $t_options); $info =& $this->_createPreferenceInformation($notifyEvents); $collection->add($info); unset($info); } }
/** * Get & build config items from Manifesto by specific module object. */ function &getConfigInfosFromManifesto(&$module) { $configInfos = $module->getInfo('config'); // // Insert comment config by old style. // if ($module->getVar('hascomments') != 0) { require_once XOOPS_ROOT_PATH . "/include/comment_constants.php"; $configInfos[] = array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN)); $configInfos[] = array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0); } // // Insert comment config by old style. // if ($module->get('hasnotification') != 0) { require_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; require_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; $t_options = array(); $t_options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE; $t_options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK; $t_options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE; $t_options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH; $configInfos[] = array('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options' => $t_options); // // FIXME: doesn't work when update module... can't read back the // array of options properly... " changing to " // unset($t_options); $t_options = array(); $t_categoryArr =& notificationCategoryInfo('', $module->get('mid')); foreach ($t_categoryArr as $t_category) { $t_eventArr =& notificationEvents($t_category['name'], false, $module->get('mid')); foreach ($t_eventArr as $t_event) { if (!empty($t_event['invisible'])) { continue; } $t_optionName = $t_category['title'] . ' : ' . $t_event['title']; $t_options[$t_optionName] = $t_category['name'] . '-' . $t_event['name']; } } $configInfos[] = array('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($t_options), 'options' => $t_options); } return $configInfos; }
/** * Get an array of associative info arrays for subscribable categories * for the selected module. * * @param int $module_id ID of the module * @return mixed */ function ¬ificationSubscribableCategoryInfo($module_id = null) { $all_categories =& notificationCategoryInfo('', $module_id); // FIXME: better or more standardized way to do this? $script_url = explode('/', $_SERVER['PHP_SELF']); $script_name = $script_url[count($script_url) - 1]; $sub_categories = array(); foreach ($all_categories as $category) { // Check the script name $subscribe_from = $category['subscribe_from']; if (!is_array($subscribe_from)) { if ($subscribe_from == '*') { $subscribe_from = array($script_name); // FIXME: this is just a hack: force a match } else { $subscribe_from = array($subscribe_from); } } if (!in_array($script_name, $subscribe_from)) { continue; } // If 'item_name' is missing, automatic match. Otherwise // check if that argument exists... if (empty($category['item_name'])) { $category['item_name'] = ''; $category['item_id'] = 0; $sub_categories[] = $category; } else { $item_name = $category['item_name']; $id = $item_name != '' && isset($_GET[$item_name]) ? intval($_GET[$item_name]) : 0; if ($id > 0) { $category['item_id'] = $id; $sub_categories[] = $category; } } } return $sub_categories; }
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); } } }
/** * Get an array of associative info arrays for subscribable categories * for the selected module. * * @param int $module_id ID of the module * @return mixed */ function ¬ificationSubscribableCategoryInfo($module_id = null) { $all_categories =& notificationCategoryInfo('', $module_id); // FIXME: better or more standardized way to do this? $script_url = explode('/', $_SERVER['SCRIPT_NAME']); $script_name = $script_url[count($script_url) - 1]; $sub_categories = array(); foreach ($all_categories as $category) { // Check the script name $subscribe_from = $category['subscribe_from']; if (!is_array($subscribe_from)) { if ($subscribe_from == '*') { $subscribe_from = array($script_name); // FIXME: this is just a hack: force a match } else { $subscribe_from = array($subscribe_from); } } if (!in_array($script_name, $subscribe_from)) { continue; } // If 'item_name' is missing, automatic match. Otherwise // check if that argument exists... if (empty($category['item_name'])) { $category['item_name'] = ''; $category['item_id'] = 0; $sub_categories[] = $category; } else { $item_name = $category['item_name']; global $HTTP_GET_VARS; $id = $item_name != '' && isset($HTTP_GET_VARS[$item_name]) ? intval($HTTP_GET_VARS[$item_name]) : 0; if ($id > 0) { $category['item_id'] = $id; $sub_categories[] = $category; } } } // TODO: switch to $_GET instead of $HTTP_GET_VARS. But also // in wiki need to switch, because we are SETTING the get vars // so we have the itemid always present even on default homepage return $sub_categories; }
function getDefaultView(&$contoller, &$xoopsUser) { $criteria = new Criteria('not_uid', $xoopsUser->get('uid')); $criteria->setSort('not_modid, not_category, not_itemid'); $handler =& xoops_gethandler('notification'); $notificationArr =& $handler->getObjects($criteria); $moduleHandler =& xoops_gethandler('module'); $prev_modid = -1; $prev_category = -1; $prev_item = -1; foreach ($notificationArr as $notify) { $t_modid = $notify->get('not_modid'); $module =& $moduleHandler->get($t_modid); if (!is_object($module)) { continue; } if ($t_modid != $prev_modid) { $prev_modid = $t_modid; $prev_category = -1; $prev_item = -1; $this->mModules[$t_modid] = array('id' => $t_modid, 'name' => $module->getShow('name'), 'categories' => array()); // // [ToDo] (Original) // note, we could auto-generate the url from the id // and category info... (except when category has multiple // subscription scripts defined...) // OR, add one more option to xoops_version 'view_from' // which tells us where to redirect... BUT, e.g. forums, it // still wouldn't give us all the required info... e.g. the // topic ID doesn't give us the ID of the forum which is // a required argument... // // Get the lookup function, if exists // $notifyConfig = $module->getInfo('notification'); $lookupFunc = ''; if (!empty($notifyConfig['lookup_file'])) { $t_filepath = XOOPS_ROOT_PATH . '/modules/' . $module->get('dirname') . '/' . $notifyConfig['lookup_file']; if (file_exists($t_filepath)) { require_once $t_filepath; if (!empty($notifyConfig['lookup_func']) && function_exists($notifyConfig['lookup_func'])) { $lookupFunc = $notifyConfig['lookup_func']; } } } } $t_category = $notify->get('not_category'); if ($t_category != $prev_category) { $prev_category = $t_category; $prev_item = -1; $categoryInfo =& notificationCategoryInfo($t_category, $t_modid); } $t_item = $notify->get('not_itemid'); if ($t_item != $prev_item) { $prev_item = $t_item; if (!empty($lookupFunc)) { $itemInfo = $lookupFunc($t_category, $t_item); } else { $itemInfo = array('name' => '[' . _NOT_NAMENOTAVAILABLE . ']', 'url' => ''); } $this->mModules[$t_modid]['categories'][$t_category]['items'][$t_item] = array('id' => $t_item, 'name' => $itemInfo['name'], 'url' => $itemInfo['url'], 'notifications' => array()); } $eventInfo =& notificationEventInfo($t_category, $notify->get('not_event'), $notify->get('not_modid')); $this->mModules[$t_modid]['categories'][$t_category]['items'][$t_item]['notifications'][] = array('id' => $notify->get('not_id'), 'module_id' => $notify->get('not_modid'), 'category' => $notify->get('not_category'), 'category_title' => $categoryInfo['title'], 'item_id' => $notify->get('not_itemid'), 'event' => $notify->get('not_event'), 'event_title' => $eventInfo['title'], 'user_id' => $notify->get('not_uid')); } return LEGACY_FRAME_VIEW_INDEX; }
/** * Insert configuration items * * @return void */ function insertConfig() { $configs = $this->getInfo('config'); if ($configs == false) { $configs = array(); } if ($this->getVar('hascomments') != 0) { include_once XOOPS_ROOT_PATH . '/include/comment_constants.php'; array_push($configs, array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN))); array_push($configs, array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0)); } // RMV-NOTIFY if ($this->getVar('hasnotification') != 0) { if (empty($configs)) { $configs = array(); } // Main notification options include_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; include_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; $options = array(); $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE; $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK; $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE; $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH; $configs[] = array('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options' => $options); // Event-specific notification options // FIXME: doesn't work when update module... can't read back the array of options properly... " changing to " $options = array(); $categories =& notificationCategoryInfo('', $this->getVar('mid')); foreach ($categories as $category) { $events =& notificationEvents($category['name'], false, $this->getVar('mid')); foreach ($events as $event) { if (!empty($event['invisible'])) { continue; } $option_name = $category['title'] . ' : ' . $event['title']; $option_value = $category['name'] . '-' . $event['name']; $options[$option_name] = $option_value; } } $configs[] = array('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($options), 'options' => $options); } if ($configs != false) { $confcat_handler =& xoops_gethandler('configcategory'); /* @var $confcat_handler XoopsConfigCategoryHandler */ $confcats =& $confcat_handler->getCatByModule($this->getVar('mid')); if (count($confcats) > 0) { foreach (array_keys($confcats) as $i) { //get categories by confcat_nameid $cats[$confcats[$i]->getVar('confcat_nameid')] = $confcats[$i]->getVar('confcat_id'); } } $this->setMessage('Adding module config data...'); $config_handler =& xoops_gethandler('config'); $configcriteria = new Criteria('conf_modid', $this->getVar('mid')); $old_configs =& $config_handler->getConfigs($configcriteria, false, true); unset($configcriteria); foreach ($configs as $config) { $configs_name[] = $config["name"]; } foreach (array_keys($old_configs) as $i) { if (!in_array($old_configs[$i]->getVar('conf_name'), $configs_name)) { $config_handler->deleteConfig($old_configs[$i]); continue; } $conf_arr[$old_configs[$i]->getVar('conf_name')] =& $old_configs[$i]; } $order = 0; foreach ($configs as $config) { if (isset($conf_arr[$config['name']])) { $confobj =& $conf_arr[$config['name']]; } else { $confobj =& $config_handler->createConfig(); } $confcat_nameid = isset($config['category']) ? $config['category'] : 'xoops_default'; $confobj->setVar('conf_modid', $this->getVar('mid')); $confobj->setVar('conf_catid', $cats[$confcat_nameid]); $confobj->setVar('conf_name', $config['name']); $confobj->setVar('conf_title', $config['title'], true); $confobj->setVar('conf_desc', $config['description'], true); $confobj->setVar('conf_formtype', $config['formtype']); $confobj->setVar('conf_valuetype', $config['valuetype']); //$confobj->setVar('conf_value', $config['default'], true); $confobj->setVar('conf_order', $order); if ($confobj->isNew()) { // Only set configuration value to default on new configs $confobj->setConfValueForInput($config['default'], true); } $confop_msgs = ''; if (isset($config['options']) && is_array($config['options'])) { $options =& $confobj->getConfOptions(); if (count($options) > 0) { foreach (array_keys($options) as $i) { $existing_options[$options[$i]->getVar('confop_name')] = $options[$i]->getVar('confop_value'); } $newoptions = xoops_array_diff_assoc($config['options'], $existing_options); $removedoptions = xoops_array_diff_assoc($existing_options, $config['options']); unset($existing_options); } else { $newoptions = $config['options']; $removedoptions = array(); } //clear config options from config items $confobj->clearConfOptions(); if (count($newoptions) > 0) { foreach ($newoptions as $key => $value) { $confop =& $config_handler->createConfigOption(); $confop->setVar('confop_name', $key, true); $confop->setVar('confop_value', $value, true); $confobj->setConfOptions($confop); $confop_msgs .= '<br /> Config option added. Name: <b>' . $key . '</b> Value: <b>' . $value . '</b>'; unset($confop); } } if (count($removedoptions) > 0) { foreach ($removedoptions as $key => $value) { $deletecriteria = new CriteriaCompo(new Criteria('confop_name', $key)); $deletecriteria->add(new Criteria('confop_value', $value)); $deletecriteria->add(new Criteria('conf_id', $confobj->getVar('conf_id'))); $config_handler->deleteConfigOption($deletecriteria); unset($deletecriteria); $confop_msgs .= '<br /> Config option removed. Name: <b>' . $key . '</b> Value: <b>' . $value . '</b>'; } } } $order++; if ($config_handler->insertConfig($confobj) != false) { $this->setMessage(' Config <b>' . $config['name'] . '</b> added to the database.' . $confop_msgs); } else { $this->setMessage(' <span style="color:#ff0000;">ERROR: Could not insert config <b>' . $config['name'] . '</b> to the database.</span>'); } unset($confobj); } unset($configs); } }
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 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 xoops_module_install($dirname) { global $xoopsUser, $xoopsConfig; $dirname = trim($dirname); $db =& $GLOBALS["xoopsDB"]; $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish'); $module_handler =& xoops_gethandler('module'); if ($module_handler->getCount(new Criteria('dirname', $dirname)) == 0) { $module =& $module_handler->create(); $module->loadInfoAsVar($dirname); $module->setVar('weight', 1); $error = false; $errs = array(); $msgs = array(); $msgs[] = '<h4 style="margin-bottom: 0px;border-bottom: dashed 1px #000000;">' . _MD_AM_INSTALLING . $module->getInfo('name') . '</h4>'; if ($module->getInfo('image') != false && trim($module->getInfo('image')) != '') { $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" />'; } $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version'); if ($module->getInfo('author') != false && trim($module->getInfo('author')) != '') { $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . trim($module->getInfo('author')); } $msgs[] = ''; $errs[] = '<h4 style="margin-bottom: 0px;border-bottom: dashed 1px #000000;">' . _MD_AM_INSTALLING . $module->getInfo('name') . '</h4>'; // Load module specific install script if any $install_script = $module->getInfo('onInstall'); if ($install_script && trim($install_script) != '') { include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($install_script); } $func = "xoops_module_pre_install_{$dirname}"; // If pre install function is defined, execute if (function_exists($func)) { $result = $func($module); if (!$result) { $error = true; $errs[] = "<p>" . sprintf(_MD_AM_FAILED_EXECUTE, $func) . "</p>"; $errs = array_merge($errs, $module->getErrors()); } else { $msgs[] = "<p>" . sprintf(_MD_AM_FAILED_SUCESS, "<strong>{$func}</strong>") . "</p>"; $msgs += $module->getErrors(); } } if ($error == false) { $sqlfile = $module->getInfo('sqlfile'); if (is_array($sqlfile) && !empty($sqlfile[XOOPS_DB_TYPE])) { $sql_file_path = XOOPS_ROOT_PATH . "/modules/" . $dirname . "/" . $sqlfile[XOOPS_DB_TYPE]; if (!file_exists($sql_file_path)) { $errs[] = "<p>" . sprintf(_MD_AM_SQL_NOT_FOUND, "<strong>{$sql_file_path}</strong>"); $error = true; } else { $msgs[] = "<p>" . sprintf(_MD_AM_SQL_FOUND, "<strong>{$sql_file_path}</strong>") . "<br />" . _MD_AM_CREATE_TABLES; include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php'; $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path)); $sql_query = trim($sql_query); SqlUtility::splitMySqlFile($pieces, $sql_query); $created_tables = array(); foreach ($pieces as $piece) { // [0] contains the prefixed query // [4] contains unprefixed table name $prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix()); if (!$prefixed_query) { $errs[] = "<p>" . sprintf(_MD_AM_SQL_NOT_VALID, "<strong>" . $piece . "</strong>"); $error = true; break; } // check if the table name is reserved if (!in_array($prefixed_query[4], $reservedTables)) { // not reserved, so try to create one if (!$db->query($prefixed_query[0])) { $errs[] = $db->error(); $error = true; break; } else { if (!in_array($prefixed_query[4], $created_tables)) { $msgs[] = " " . sprintf(_MD_AM_TABLE_CREATED, "<strong>" . $db->prefix($prefixed_query[4]) . "</strong>"); $created_tables[] = $prefixed_query[4]; } else { $msgs[] = " " . sprintf(_MD_AM_INSERT_DATA, "<strong>" . $db->prefix($prefixed_query[4]) . "</strong>"); } } } else { // the table name is reserved, so halt the installation $errs[] = " " . sprintf(_MD_AM_TABLE_RESERVED, "<strong>" . $prefixed_query[4] . "</strong>"); $error = true; break; } } // if there was an error, delete the tables created so far, so the next installation will not fail if ($error == true) { foreach ($created_tables as $ct) { $db->query("DROP TABLE " . $db->prefix($ct)); } } } } } // if no error, save the module info and blocks info associated with it if ($error == false) { if (!$module_handler->insert($module)) { $errs[] = "<p>" . sprintf(_MD_AM_INSERT_DATA_FAILD, "<strong>" . $module->getVar('name') . "</strong>"); foreach ($created_tables as $ct) { $db->query("DROP TABLE " . $db->prefix($ct)); } $ret = "<p>" . sprintf(_MD_AM_FAILINS, "<strong>" . $module->name() . "</strong>") . " " . _MD_AM_ERRORSC . "<br />"; foreach ($errs as $err) { $ret .= " - " . $err . "<br />"; } $ret .= "</p>"; unset($module); unset($created_tables); unset($errs); unset($msgs); return $ret; } else { $newmid = $module->getVar('mid'); unset($created_tables); $msgs[] = "<p>" . _MD_AM_INSERT_DATA_DONE . sprintf(_MD_AM_MODULEID, "<strong>" . $newmid . "</strong>"); $tplfile_handler =& xoops_gethandler('tplfile'); $templates = $module->getInfo('templates'); if ($templates != false) { $msgs[] = _MD_AM_TEMPLATES_ADD; foreach ($templates as $tpl) { $tplfile =& $tplfile_handler->create(); $tpldata =& xoops_module_gettemplate($dirname, $tpl['file']); $tplfile->setVar('tpl_source', $tpldata, true); $tplfile->setVar('tpl_refid', $newmid); $tplfile->setVar('tpl_tplset', 'default'); $tplfile->setVar('tpl_file', $tpl['file']); $tplfile->setVar('tpl_desc', $tpl['description'], true); $tplfile->setVar('tpl_module', $dirname); $tplfile->setVar('tpl_lastmodified', time()); $tplfile->setVar('tpl_lastimported', 0); $tplfile->setVar('tpl_type', 'module'); if (!$tplfile_handler->insert($tplfile)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_MD_AM_TEMPLATE_ADD_ERROR, "<strong>" . $tpl['file'] . "</strong>") . "</span>"; } else { $newtplid = $tplfile->getVar('tpl_id'); $msgs[] = " " . sprintf(_MD_AM_TEMPLATE_ADD_DATA, "<strong>" . $tpl['file'] . "</strong>") . "(ID: <strong>" . $newtplid . "</strong>)"; // generate compiled file include_once XOOPS_ROOT_PATH . '/class/template.php'; if (!xoops_template_touch($newtplid)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_MD_AM_TEMPLATE_COMPILED_FAILED, "<strong>" . $tpl['file'] . "</strong>") . "</span>"; } else { $msgs[] = " " . sprintf(_MD_AM_TEMPLATE_COMPILED, "<strong>" . $tpl['file'] . "</strong>"); } } unset($tplfile, $tpldata); } } include_once XOOPS_ROOT_PATH . '/class/template.php'; xoops_template_clear_module_cache($newmid); $blocks = $module->getInfo('blocks'); if ($blocks != false) { $msgs[] = _MD_AM_BLOCKS_ADD; foreach ($blocks as $blockkey => $block) { // break the loop if missing block config if (!isset($block['file']) || !isset($block['show_func'])) { break; } $options = ''; if (!empty($block['options'])) { $options = trim($block['options']); } $newbid = $db->genId($db->prefix('newblocks') . '_bid_seq'); $edit_func = isset($block['edit_func']) ? trim($block['edit_func']) : ''; $template = ''; if (isset($block['template']) && trim($block['template']) != '') { $content =& xoops_module_gettemplate($dirname, $block['template'], true); } if (empty($content)) { $content = ''; } else { $template = trim($block['template']); } $block_name = addslashes(trim($block['name'])); $sql = "INSERT INTO " . $db->prefix("newblocks") . " (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, c_type, isactive, dirname, func_file, show_func, edit_func, template, bcachetime, last_modified) VALUES ({$newbid}, {$newmid}, " . intval($blockkey) . ", '{$options}', '" . $block_name . "','" . $block_name . "', '', 0, 0, 0, 'M', 'H', 1, '" . addslashes($dirname) . "', '" . addslashes(trim($block['file'])) . "', '" . addslashes(trim($block['show_func'])) . "', '" . addslashes($edit_func) . "', '" . $template . "', 0, " . time() . ")"; if (!$db->query($sql)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_MD_AM_BLOCK_ADD_ERROR, "<strong>" . $block['name'] . "</strong>") . sprintf(_MD_AM_BLOCK_ADD_ERROR_DATABASE, "<strong>" . $db->error() . "</strong>") . "</span>"; } else { if (empty($newbid)) { $newbid = $db->getInsertId(); } $msgs[] = " " . sprintf(_MD_AM_BLOCK_ADD, "<strong>" . $block['name'] . "</strong>") . sprintf(_MD_AM_BLOCK_ID, "<strong>" . $newbid . "</strong>"); $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)'; $db->query($sql); if ($template != '') { $tplfile =& $tplfile_handler->create(); $tplfile->setVar('tpl_refid', $newbid); $tplfile->setVar('tpl_source', $content, true); $tplfile->setVar('tpl_tplset', 'default'); $tplfile->setVar('tpl_file', $block['template']); $tplfile->setVar('tpl_module', $dirname); $tplfile->setVar('tpl_type', 'block'); $tplfile->setVar('tpl_desc', $block['description'], true); $tplfile->setVar('tpl_lastimported', 0); $tplfile->setVar('tpl_lastmodified', time()); if (!$tplfile_handler->insert($tplfile)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_MD_AM_TEMPLATE_ADD_ERROR, "<strong>" . $block['template'] . "</strong>") . "</span>"; } else { $newtplid = $tplfile->getVar('tpl_id'); $msgs[] = " " . sprintf(_MD_AM_TEMPLATE_ADD_DATA, "<strong>" . $block['template'] . "</strong>") . " (ID: <strong>" . $newtplid . "</strong>)"; // generate compiled file include_once XOOPS_ROOT_PATH . '/class/template.php'; if (!xoops_template_touch($newtplid)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_MD_AM_TEMPLATE_COMPILED_FAILED, "<strong>" . $block['template'] . "</strong>") . "</span>"; } else { $msgs[] = " " . sprintf(_MD_AM_TEMPLATE_COMPILED, "<strong>" . $block['template'] . "</strong>"); } } unset($tplfile); } } unset($content); } unset($blocks); } $configs = $module->getInfo('config'); if ($configs != false) { if ($module->getVar('hascomments') != 0) { include_once XOOPS_ROOT_PATH . '/include/comment_constants.php'; array_push($configs, array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN))); array_push($configs, array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0)); } } else { if ($module->getVar('hascomments') != 0) { $configs = array(); include_once XOOPS_ROOT_PATH . '/include/comment_constants.php'; $configs[] = array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN)); $configs[] = array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0); } } // RMV-NOTIFY if ($module->getVar('hasnotification') != 0) { if (empty($configs)) { $configs = array(); } // Main notification options include_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; include_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; $options = array(); $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE; $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK; $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE; $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH; $configs[] = array('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options' => $options); // Event-specific notification options // FIXME: doesn't work when update module... can't read back the array of options properly... " changing to " $options = array(); $categories =& notificationCategoryInfo('', $module->getVar('mid')); foreach ($categories as $category) { $events =& notificationEvents($category['name'], false, $module->getVar('mid')); foreach ($events as $event) { if (!empty($event['invisible'])) { continue; } $option_name = $category['title'] . ' : ' . $event['title']; $option_value = $category['name'] . '-' . $event['name']; $options[$option_name] = $option_value; } unset($events); } unset($categories); $configs[] = array('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($options), 'options' => $options); } if ($configs != false) { $msgs[] = _MD_AM_MODULE_DATA_ADD; $config_handler =& xoops_gethandler('config'); $order = 0; foreach ($configs as $config) { $confobj =& $config_handler->createConfig(); $confobj->setVar('conf_modid', $newmid); $confobj->setVar('conf_catid', 0); $confobj->setVar('conf_name', $config['name']); $confobj->setVar('conf_title', $config['title'], true); $confobj->setVar('conf_desc', $config['description'], true); $confobj->setVar('conf_formtype', $config['formtype']); $confobj->setVar('conf_valuetype', $config['valuetype']); $confobj->setConfValueForInput($config['default'], true); $confobj->setVar('conf_order', $order); $confop_msgs = ''; if (isset($config['options']) && is_array($config['options'])) { foreach ($config['options'] as $key => $value) { $confop =& $config_handler->createConfigOption(); $confop->setVar('confop_name', $key, true); $confop->setVar('confop_value', $value, true); $confobj->setConfOptions($confop); $confop_msgs .= '<br /> ' . _MD_AM_CONFIG_ADD . _MD_AM_NAME . ' <strong>' . (defined($key) ? constant($key) : $key) . '</strong> ' . _MD_AM_VALUE . ' <strong>' . $value . '</strong> '; unset($confop); } } $order++; if ($config_handler->insertConfig($confobj) != false) { $msgs[] = ' ' . sprintf(_MD_AM_CONFIG_DATA_ADD, "<strong>" . $config['name'] . "</strong>") . $confop_msgs; } else { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_MD_AM_CONFIG_DATA_ADD_ERROR, "<strong>" . $config['name'] . "</strong>") . "</span>"; } unset($confobj); } unset($configs); } } if ($module->getInfo('hasMain')) { $groups = array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS); } else { $groups = array(XOOPS_GROUP_ADMIN); } // retrieve all block ids for this module $blocks = XoopsBlock::getByModule($newmid, false); $msgs[] = _MD_AM_GROUP_SETTINGS_ADD; $gperm_handler =& xoops_gethandler('groupperm'); foreach ($groups as $mygroup) { if ($gperm_handler->checkRight('module_admin', 0, $mygroup)) { $mperm =& $gperm_handler->create(); $mperm->setVar('gperm_groupid', $mygroup); $mperm->setVar('gperm_itemid', $newmid); $mperm->setVar('gperm_name', 'module_admin'); $mperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($mperm)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_MD_AM_ACCESS_ADMIN_ADD_ERROR, "<strong>" . $mygroup . "</strong>") . "</span>"; } else { $msgs[] = " " . sprintf(_MD_AM_ACCESS_ADMIN_ADD, "<strong>" . $mygroup . "</strong>"); } unset($mperm); } $mperm =& $gperm_handler->create(); $mperm->setVar('gperm_groupid', $mygroup); $mperm->setVar('gperm_itemid', $newmid); $mperm->setVar('gperm_name', 'module_read'); $mperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($mperm)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_MD_AM_ACCESS_USER_ADD_ERROR, "<strong>" . $mygroup . "</strong>") . "</span>"; } else { $msgs[] = ' ' . sprintf(_MD_AM_ACCESS_USER_ADD_ERROR, "<strong>" . $mygroup . "</strong>"); } unset($mperm); foreach ($blocks as $blc) { $bperm =& $gperm_handler->create(); $bperm->setVar('gperm_groupid', $mygroup); $bperm->setVar('gperm_itemid', $blc); $bperm->setVar('gperm_name', 'block_read'); $bperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($bperm)) { $msgs[] = ' <span style="color:#ff0000;">' . _MD_AM_BLOCK_ACCESS_ERROR . ' Block ID: <strong>' . $blc . '</strong> Group ID: <strong>' . $mygroup . '</strong></span>'; } else { $msgs[] = ' ' . _MD_AM_BLOCK_ACCESS . sprintf(_MD_AM_BLOCK_ID, "<strong>" . $blc . "</strong>") . sprintf(_MD_AM_GROUP_ID, "<strong>" . $mygroup . "</strong>"); } unset($bperm); } } unset($blocks); unset($groups); // execute module specific install script if any $func = "xoops_module_install_{$dirname}"; if (function_exists($func)) { if (!($lastmsg = $func($module))) { $msgs[] = "<p>" . sprintf(_MD_AM_FAILED_EXECUTE, $func) . "</p>"; } else { $msgs[] = "<p>" . sprintf(_MD_AM_FAILED_SUCESS, "<strong>{$func}</strong>") . "</p>"; if (is_string($lastmsg)) { $msgs[] = $lastmsg; } } } $ret = '<div>' . implode("<br />", $msgs) . '</div><br />' . sprintf(_MD_AM_OKINS, "<strong>" . $module->getVar('name') . "</strong>"); unset($msgs); unset($errs); unset($module); return $ret; } else { $ret = '<p>' . sprintf(_MD_AM_FAILINS, '<strong>' . $dirname . '</strong>') . ' ' . _MD_AM_ERRORSC . '<br />' . implode("<br />", $errs) . '</p>'; unset($msgs); unset($errs); return $ret; } } else { return "<p>" . sprintf(_MD_AM_FAILINS, "<strong>" . $dirname . "</strong>") . " " . _MD_AM_ERRORSC . "<br /> " . sprintf(_MD_AM_ALEXISTS, $dirname) . "</p>"; } }
} // Main notification options include_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; include_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; $options = array(); $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE; $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK; $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE; $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH; //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1); $configs[] = array('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options' => $options); // Event specific notification options // FIXME: for some reason the default doesn't come up properly // initially is ok, but not when 'update' module.. $options = array(); $categories =& notificationCategoryInfo('', $module->getVar('mid')); foreach ($categories as $category) { $events =& notificationEvents($category['name'], false, $module->getVar('mid')); foreach ($events as $event) { if (!empty($event['invisible'])) { continue; } $option_name = $category['title'] . ' : ' . $event['title']; $option_value = $category['name'] . '-' . $event['name']; $options[$option_name] = $option_value; //$configs[] = array ('name' => notificationGenerateConfig($category,$event,'name'), 'title' => notificationGenerateConfig($category,$event,'title_constant'), 'description' => notificationGenerateConfig($category,$event,'description_constant'), 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1); } } $configs[] = array('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($options), 'options' => $options); } if ($configs != false) {
/** * @param $dirname * @return string */ function xoops_module_update($dirname) { global $xoopsUser, $xoopsConfig, $xoopsTpl; $dirname = trim($dirname); $xoopsDB =& $GLOBALS['xoopsDB']; $myts = MyTextSanitizer::getInstance(); $dirname = $myts->htmlspecialchars(trim($dirname)); $module_handler = xoops_getHandler('module'); $module = $module_handler->getByDirname($dirname); // Save current version for use in the update function $prev_version = $module->getVar('version'); $clearTpl = new XoopsTpl(); $clearTpl->clearCache($dirname); // we don't want to change the module name set by admin $temp_name = $module->getVar('name'); $module->loadInfoAsVar($dirname); $module->setVar('name', $temp_name); $module->setVar('last_update', time()); /* // Call Header // Define main template $GLOBALS['xoopsOption']['template_main'] = 'system_header.html'; // Call Header xoops_cp_header(); // Define Stylesheet $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/admin.css'); // Define Breadcrumb and tips $xoBreadCrumb->addLink(_AM_SYSTEM_MODULES_ADMIN, system_adminVersion('modulesadmin', 'adminpath')); $xoBreadCrumb->addLink(_AM_SYSTEM_MODULES_UPDATE); $xoBreadCrumb->addHelp(system_adminVersion('modulesadmin', 'help') . '#update');https://www.facebook.com/photo.php?v=10154358806675333 $xoBreadCrumb->render(); */ if (!$module_handler->insert($module)) { echo '<p>Could not update ' . $module->getVar('name') . '</p>'; echo "<br><div class='center'><a href='admin.php?fct=modulesadmin'>" . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>'; } else { $newmid = $module->getVar('mid'); $msgs = array(); $msgs[] = '<div id="xo-module-log"><div class="header">'; $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_UPDATING . $module->getInfo('name', 's') . '</h4>'; if ($module->getInfo('image') != false && trim($module->getInfo('image')) != '') { $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" />'; } $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version') . ' ' . $module->getInfo('module_status'); if ($module->getInfo('author') != false && trim($module->getInfo('author')) != '') { $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . $myts->htmlspecialchars(trim($module->getInfo('author'))); } $msgs[] = '</div><div class="logger">'; $update_script = $module->getInfo('onUpdate'); if (!empty($update_script) && trim($update_script) != '') { include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($update_script); } // execute module specific update script if any if (function_exists('xoops_module_pre_update_' . $dirname)) { $func = 'xoops_module_pre_update_' . $dirname; if (!$func($module, $prev_version)) { $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>'; $msgs = array_merge($msgs, $module->getErrors()); } else { $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, '<strong>' . $func . '</strong>') . '</p>'; $msgs += $module->getErrors(); } } $msgs[] = _AM_SYSTEM_MODULES_MODULE_DATA_UPDATE; $tplfile_handler = xoops_getHandler('tplfile'); // irmtfan bug fix: remove codes for delete templates /* $deltpl = $tplfile_handler->find('default', 'module', $module->getVar('mid')); $delng = array(); if (is_array($deltpl)) { // delete template file entry in db $dcount = count($deltpl); for ($i = 0; $i < $dcount; $i++) { if (!$tplfile_handler->delete($deltpl[$i])) { $delng[] = $deltpl[$i]->getVar('tpl_file'); } } } */ // irmtfan bug fix: remove codes for delete templates $templates = $module->getInfo('templates'); if ($templates != false) { $msgs[] = _AM_SYSTEM_MODULES_TEMPLATES_UPDATE; foreach ($templates as $tpl) { $tpl['file'] = trim($tpl['file']); // START irmtfan solve templates duplicate issue // if (!in_array($tpl['file'], $delng)) { // irmtfan bug fix: remove codes for delete templates $type = isset($tpl['type']) ? $tpl['type'] : 'module'; if (preg_match("/\\.css\$/i", $tpl['file'])) { $type = 'css'; } $criteria = new CriteriaCompo(); $criteria->add(new Criteria('tpl_refid', $newmid), 'AND'); $criteria->add(new Criteria('tpl_module', $dirname), 'AND'); $criteria->add(new Criteria('tpl_tplset', 'default'), 'AND'); $criteria->add(new Criteria('tpl_file', $tpl['file']), 'AND'); $criteria->add(new Criteria('tpl_type', $type), 'AND'); $tplfiles = $tplfile_handler->getObjects($criteria); $tpldata =& xoops_module_gettemplate($dirname, $tpl['file'], $type); $tplfile = empty($tplfiles) ? $tplfile_handler->create() : $tplfiles[0]; // END irmtfan solve templates duplicate issue $tplfile->setVar('tpl_refid', $newmid); $tplfile->setVar('tpl_lastimported', 0); $tplfile->setVar('tpl_lastmodified', time()); $tplfile->setVar('tpl_type', $type); $tplfile->setVar('tpl_source', $tpldata, true); $tplfile->setVar('tpl_module', $dirname); $tplfile->setVar('tpl_tplset', 'default'); $tplfile->setVar('tpl_file', $tpl['file'], true); $tplfile->setVar('tpl_desc', $tpl['description'], true); if (!$tplfile_handler->insert($tplfile)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, '<strong>' . $tpl['file'] . '</strong>') . '</span>'; } else { $newid = $tplfile->getVar('tpl_id'); $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_INSERT_DATA, '<strong>' . $tpl['file'] . '</strong>'); if ($xoopsConfig['template_set'] === 'default') { if (!xoops_template_touch($newid)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_ERROR, '<strong>' . $tpl['file'] . '</strong>') . '</span>'; } else { $msgs[] = ' <span>' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, '<strong>' . $tpl['file'] . '</strong>') . '</span>'; } } } unset($tpldata); // irmtfan bug fix: remove codes for delete templates /* } else { $msgs[] = ' <span style="color:#ff0000;">'.sprintf(_AM_SYSTEM_MODULES_TEMPLATE_DELETE_OLD_ERROR, "<strong>".$tpl['file']."</strong>").'</span>'; } */ // irmtfan bug fix: remove codes for delete templates } } $blocks = $module->getInfo('blocks'); $msgs[] = _AM_SYSTEM_MODULES_BLOCKS_REBUILD; if ($blocks != false) { $showfuncs = array(); $funcfiles = array(); foreach ($blocks as $i => $block) { if (isset($block['show_func']) && $block['show_func'] != '' && isset($block['file']) && $block['file'] != '') { $editfunc = isset($block['edit_func']) ? $block['edit_func'] : ''; $showfuncs[] = $block['show_func']; $funcfiles[] = $block['file']; $template = ''; if (isset($block['template']) && trim($block['template']) != '') { $content =& xoops_module_gettemplate($dirname, $block['template'], 'blocks'); } if (!$content) { $content = ''; } else { $template = $block['template']; } $options = ''; if (!empty($block['options'])) { $options = $block['options']; } $sql = 'SELECT bid, name FROM ' . $xoopsDB->prefix('newblocks') . ' WHERE mid=' . $module->getVar('mid') . ' AND func_num=' . $i . " AND show_func='" . addslashes($block['show_func']) . "' AND func_file='" . addslashes($block['file']) . "'"; $fresult = $xoopsDB->query($sql); $fcount = 0; while ($fblock = $xoopsDB->fetchArray($fresult)) { ++$fcount; $sql = 'UPDATE ' . $xoopsDB->prefix('newblocks') . " SET name='" . addslashes($block['name']) . "', edit_func='" . addslashes($editfunc) . "', content='', template='" . $template . "', last_modified=" . time() . ' WHERE bid=' . $fblock['bid']; $result = $xoopsDB->query($sql); if (!$result) { $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_UPDATE_ERROR, $fblock['name']); } else { $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_BLOCK_UPDATE, $fblock['name']) . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $fblock['bid'] . '</strong>'); if ($template != '') { $tplfile = $tplfile_handler->find('default', 'block', $fblock['bid']); if (count($tplfile) == 0) { $tplfile_new = $tplfile_handler->create(); $tplfile_new->setVar('tpl_module', $dirname); $tplfile_new->setVar('tpl_refid', $fblock['bid']); $tplfile_new->setVar('tpl_tplset', 'default'); $tplfile_new->setVar('tpl_file', $block['template'], true); $tplfile_new->setVar('tpl_type', 'block'); } else { $tplfile_new = $tplfile[0]; } $tplfile_new->setVar('tpl_source', $content, true); $tplfile_new->setVar('tpl_desc', $block['description'], true); $tplfile_new->setVar('tpl_lastmodified', time()); $tplfile_new->setVar('tpl_lastimported', 0); $tplfile_new->setVar('tpl_file', $block['template'], true); // irmtfan bug fix: block template file will not updated after update the module if (!$tplfile_handler->insert($tplfile_new)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_UPDATE_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>'; } else { $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_UPDATE, '<strong>' . $block['template'] . '</strong>'); if ($xoopsConfig['template_set'] === 'default') { if (!xoops_template_touch($tplfile_new->getVar('tpl_id'))) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>'; } else { $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, '<strong>' . $block['template'] . '</strong>'); } } } } } } if ($fcount == 0) { $newbid = $xoopsDB->genId($xoopsDB->prefix('newblocks') . '_bid_seq'); $block_name = addslashes($block['name']); $block_type = $module->getVar('dirname') === 'system' ? 'S' : 'M'; $sql = 'INSERT INTO ' . $xoopsDB->prefix('newblocks') . ' (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, isactive, dirname, func_file, show_func, edit_func, template, last_modified) VALUES (' . $newbid . ', ' . $module->getVar('mid') . ', ' . $i . ",'" . addslashes($options) . "','" . $block_name . "', '" . $block_name . "', '', 0, 0, 0, '{$block_type}', 1, '" . addslashes($dirname) . "', '" . addslashes($block['file']) . "', '" . addslashes($block['show_func']) . "', '" . addslashes($editfunc) . "', '" . $template . "', " . time() . ')'; $result = $xoopsDB->query($sql); if (!$result) { $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_SQL_NOT_CREATE, $block['name']); echo $sql; } else { if (empty($newbid)) { $newbid = $xoopsDB->getInsertId(); } if ($module->getInfo('hasMain')) { $groups = array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS); } else { $groups = array(XOOPS_GROUP_ADMIN); } $gperm_handler = xoops_getHandler('groupperm'); foreach ($groups as $mygroup) { $bperm = $gperm_handler->create(); $bperm->setVar('gperm_groupid', $mygroup); $bperm->setVar('gperm_itemid', $newbid); $bperm->setVar('gperm_name', 'block_read'); $bperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($bperm)) { $msgs[] = ' <span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_BLOCK_ACCESS_ERROR . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $newbid . '</strong>') . sprintf(_AM_SYSTEM_MODULES_GROUP_ID, '<strong>' . $mygroup . '</strong>') . '</span>'; } else { $msgs[] = ' ' . _AM_SYSTEM_MODULES_BLOCK_ACCESS . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $newbid . '</strong>') . sprintf(_AM_SYSTEM_MODULES_GROUP_ID, '<strong>' . $mygroup . '</strong>'); } } if ($template != '') { $tplfile = $tplfile_handler->create(); $tplfile->setVar('tpl_module', $dirname); $tplfile->setVar('tpl_refid', $newbid); $tplfile->setVar('tpl_source', $content, true); $tplfile->setVar('tpl_tplset', 'default'); $tplfile->setVar('tpl_file', $block['template'], true); $tplfile->setVar('tpl_type', 'block'); $tplfile->setVar('tpl_lastimported', time()); $tplfile->setVar('tpl_lastmodified', time()); $tplfile->setVar('tpl_desc', $block['description'], true); if (!$tplfile_handler->insert($tplfile)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>'; } else { $newid = $tplfile->getVar('tpl_id'); $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_DATA, '<strong>' . $block['template'] . '</strong>'); if ($xoopsConfig['template_set'] === 'default') { if (!xoops_template_touch($newid)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_FAILD, '<strong>' . $block['template'] . '</strong>') . '</span>'; } else { $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, '<strong>' . $block['template'] . '</strong>'); } } } } $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_BLOCK_CREATED, '<strong>' . $block['name'] . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $newbid . '</strong>'); $sql = 'INSERT INTO ' . $xoopsDB->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)'; $xoopsDB->query($sql); } } } } $block_arr = XoopsBlock::getByModule($module->getVar('mid')); foreach ($block_arr as $block) { if (!in_array($block->getVar('show_func'), $showfuncs) || !in_array($block->getVar('func_file'), $funcfiles)) { $sql = sprintf('DELETE FROM %s WHERE bid = %u', $xoopsDB->prefix('newblocks'), $block->getVar('bid')); if (!$xoopsDB->query($sql)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE_ERROR, '<strong>' . $block->getVar('name') . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $block->getVar('bid') . '</strong>') . '</span>'; } else { $msgs[] = ' Block <strong>' . $block->getVar('name') . ' deleted. Block ID: <strong>' . $block->getVar('bid') . '</strong>'; if ($block->getVar('template') != '') { $tplfiles = $tplfile_handler->find(null, 'block', $block->getVar('bid')); if (is_array($tplfiles)) { $btcount = count($tplfiles); for ($k = 0; $k < $btcount; $k++) { if (!$tplfile_handler->delete($tplfiles[$k])) { $msgs[] = ' <span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_BLOCK_DEPRECATED_ERROR . '(ID: <strong>' . $tplfiles[$k]->getVar('tpl_id') . '</strong>)</span>'; } else { $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DEPRECATED, '<strong>' . $tplfiles[$k]->getVar('tpl_file') . '</strong>'); } } } } } } } } // reset compile_id // $xoTheme =& $xoopsThemeFactory->createInstance(array('contentTemplate' => @$GLOBALS['xoopsOption']['template_main'])); // $xoopsTpl =& $xoTheme->template; // $xoopsTpl->setCompileId(); $template = $clearTpl; $template->setCompileId(); // $GLOBALS['xoopsTpl']->setCompileId(); // $xoopsTpl->setCompileId(); // first delete all config entries $config_handler = xoops_getHandler('config'); $configs = $config_handler->getConfigs(new Criteria('conf_modid', $module->getVar('mid'))); $confcount = count($configs); $config_delng = array(); if ($confcount > 0) { $msgs[] = _AM_SYSTEM_MODULES_MODULE_DATA_DELETE; for ($i = 0; $i < $confcount; $i++) { if (!$config_handler->deleteConfig($configs[$i])) { $msgs[] = ' <span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_CONFIG_DATA_DELETE_ERROR . sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, '<strong>' . $configs[$i]->getvar('conf_id') . '</strong>') . '</span>'; // save the name of config failed to delete for later use $config_delng[] = $configs[$i]->getvar('conf_name'); } else { $config_old[$configs[$i]->getvar('conf_name')]['value'] = $configs[$i]->getvar('conf_value', 'N'); $config_old[$configs[$i]->getvar('conf_name')]['formtype'] = $configs[$i]->getvar('conf_formtype'); $config_old[$configs[$i]->getvar('conf_name')]['valuetype'] = $configs[$i]->getvar('conf_valuetype'); $msgs[] = ' ' . _AM_SYSTEM_MODULES_GONFIG_DATA_DELETE . sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, '<strong>' . $configs[$i]->getVar('conf_id') . '</strong>'); } } } // now reinsert them with the new settings $configs = $module->getInfo('config'); if ($configs != false) { if ($module->getVar('hascomments') != 0) { include_once XOOPS_ROOT_PATH . '/include/comment_constants.php'; array_push($configs, array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN))); array_push($configs, array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0)); } } else { if ($module->getVar('hascomments') != 0) { $configs = array(); include_once XOOPS_ROOT_PATH . '/include/comment_constants.php'; $configs[] = array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN)); $configs[] = array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0); } } // RMV-NOTIFY if ($module->getVar('hasnotification') != 0) { if (empty($configs)) { $configs = array(); } // Main notification options include_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; include_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; $options = array(); $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE; $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK; $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE; $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH; //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1); $configs[] = array('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options' => $options); // Event specific notification options // FIXME: for some reason the default doesn't come up properly // initially is ok, but not when 'update' module.. $options = array(); $categories =& notificationCategoryInfo('', $module->getVar('mid')); foreach ($categories as $category) { $events =& notificationEvents($category['name'], false, $module->getVar('mid')); foreach ($events as $event) { if (!empty($event['invisible'])) { continue; } $option_name = $category['title'] . ' : ' . $event['title']; $option_value = $category['name'] . '-' . $event['name']; $options[$option_name] = $option_value; //$configs[] = array ('name' => notificationGenerateConfig($category,$event,'name'), 'title' => notificationGenerateConfig($category,$event,'title_constant'), 'description' => notificationGenerateConfig($category,$event,'description_constant'), 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1); } } $configs[] = array('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($options), 'options' => $options); } if ($configs != false) { $msgs[] = 'Adding module config data...'; $config_handler = xoops_getHandler('config'); $order = 0; foreach ($configs as $config) { // only insert ones that have been deleted previously with success if (!in_array($config['name'], $config_delng)) { $confobj = $config_handler->createConfig(); $confobj->setVar('conf_modid', $newmid); $confobj->setVar('conf_catid', 0); $confobj->setVar('conf_name', $config['name']); $confobj->setVar('conf_title', $config['title'], true); $confobj->setVar('conf_desc', $config['description'], true); $confobj->setVar('conf_formtype', $config['formtype']); if (isset($config['valuetype'])) { $confobj->setVar('conf_valuetype', $config['valuetype']); } if (isset($config_old[$config['name']]['value']) && $config_old[$config['name']]['formtype'] == $config['formtype'] && $config_old[$config['name']]['valuetype'] == $config['valuetype']) { // preserver the old value if any // form type and value type must be the same $confobj->setVar('conf_value', $config_old[$config['name']]['value'], true); } else { $confobj->setConfValueForInput($config['default'], true); //$confobj->setVar('conf_value', $config['default'], true); } $confobj->setVar('conf_order', $order); $confop_msgs = ''; if (isset($config['options']) && is_array($config['options'])) { foreach ($config['options'] as $key => $value) { $confop = $config_handler->createConfigOption(); $confop->setVar('confop_name', $key, true); $confop->setVar('confop_value', $value, true); $confobj->setConfOptions($confop); $confop_msgs .= '<br> ' . _AM_SYSTEM_MODULES_CONFIG_ADD . _AM_SYSTEM_MODULES_NAME . ' <strong>' . (defined($key) ? constant($key) : $key) . '</strong> ' . _AM_SYSTEM_MODULES_VALUE . ' <strong>' . $value . '</strong> '; unset($confop); } } $order++; if (false !== $config_handler->insertConfig($confobj)) { //$msgs[] = ' Config <strong>'.$config['name'].'</strong> added to the database.'.$confop_msgs; $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD, '<strong>' . $config['name'] . '</strong>') . $confop_msgs; } else { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD_ERROR, '<strong>' . $config['name'] . '</strong>') . '</span>'; } unset($confobj); } } unset($configs); } // execute module specific update script if any if (function_exists('xoops_module_update_' . $dirname)) { $func = 'xoops_module_update_' . $dirname; if (!$func($module, $prev_version)) { $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>'; $msgs = array_merge($msgs, $module->getErrors()); } else { $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, '<strong>' . $func . '</strong>') . '</p>'; $msgs += $module->getErrors(); } } $msgs[] = sprintf(_AM_SYSTEM_MODULES_OKUPD, '<strong>' . $module->getVar('name', 's') . '</strong>'); $msgs[] = '</div></div>'; $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a> | <a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '">' . _AM_SYSTEM_MODULES_ADMIN . '</a></div>'; // foreach ($msgs as $msg) { // echo $msg . '<br>'; // } } // Call Footer // xoops_cp_footer(); // Flush cache files for cpanel GUIs // xoops_load("cpanel", "system"); // XoopsSystemCpanel::flush(); // // require_once XOOPS_ROOT_PATH . '/modules/system/class/maintenance.php'; // $maintenance = new SystemMaintenance(); // $folder = array(1, 3); // $maintenance->CleanCache($folder); //Set active modules in cache folder // xoops_setActiveModules(); // break; //----------------------------------------------- $ret = implode('<br>', $msgs); return $ret; }
$lookup_func = ''; if (!empty($not_config['lookup_file'])) { $lookup_file = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname') . '/' . $not_config['lookup_file']); if (file_exists($lookup_file)) { include_once $lookup_file; if (!empty($not_config['lookup_func']) && function_exists($not_config['lookup_func'])) { $lookup_func = $not_config['lookup_func']; } } } } $category = $n->getVar('not_category'); if ($category != $prev_category) { $prev_category = $category; $prev_item = -1; $category_info =& notificationCategoryInfo($category, $modid); $modules[$modid]['categories'][$category] = array('name' => $category, 'title' => $category_info['title'], 'items' => array()); } $item = $n->getVar('not_itemid'); if ($item != $prev_item) { $prev_item = $item; if (!empty($lookup_func)) { $item_info = $lookup_func($category, $item); } else { $item_info = array('name' => '[' . _NOT_NAMENOTAVAILABLE . ']', 'url' => ''); } $modules[$modid]['categories'][$category]['items'][$item] = array('id' => $item, 'name' => $item_info['name'], 'url' => $item_info['url'], 'notifications' => array()); } $event_info =& notificationEventInfo($category, $n->getVar('not_event'), $n->getVar('not_modid')); $modules[$modid]['categories'][$category]['items'][$item]['notifications'][] = array('id' => $n->getVar('not_id'), 'module_id' => $n->getVar('not_modid'), 'category' => $n->getVar('not_category'), 'category_title' => $category_info['title'], 'item_id' => $n->getVar('not_itemid'), 'event' => $n->getVar('not_event'), 'event_title' => $event_info['title'], 'user_id' => $n->getVar('not_uid')); }
function xoops_module_update($dirname) { global $xoopsConfig, $xoopsDB; $dirname = trim($dirname); $module_handler =& xoops_gethandler('module'); $module =& $module_handler->getByDirname($dirname); // Save current version for use in the update function $prev_version = $module->getVar('version'); include_once XOOPS_ROOT_PATH . '/class/template.php'; $xoopsTpl = new XoopsTpl(); $xoopsTpl->clearCache($dirname); //xoops_template_clear_module_cache($module->getVar('mid')); // we dont want to change the module name set by admin $temp_name = $module->getVar('name'); $module->loadInfoAsVar($dirname); $module->setVar('name', $temp_name); $log = ''; if (!$module_handler->insert($module)) { $log .= sprintf(__('Could not update %s', 'rmcommon'), $module->getVar('name')); } else { $newmid = $module->getVar('mid'); $msgs = array(); $msgs[] = sprintf(__('Updating module %s', 'rmcommon'), $module->getVar('name')); $tplfile_handler =& xoops_gethandler('tplfile'); $deltpl = $tplfile_handler->find('default', 'module', $module->getVar('mid')); $delng = array(); if (is_array($deltpl)) { // delete template file entry in db $dcount = count($deltpl); for ($i = 0; $i < $dcount; $i++) { if (!$tplfile_handler->delete($deltpl[$i])) { $delng[] = $deltpl[$i]->getVar('tpl_file'); } } } $templates = $module->getInfo('templates'); if ($templates != false) { $msgs[] = __('Updating templates...', 'rmcommon'); foreach ($templates as $tpl) { $tpl['file'] = trim($tpl['file']); if (!in_array($tpl['file'], $delng)) { $tpldata =& xoops_module_gettemplate($dirname, $tpl['file']); $tplfile =& $tplfile_handler->create(); $tplfile->setVar('tpl_refid', $newmid); $tplfile->setVar('tpl_lastimported', 0); $tplfile->setVar('tpl_lastmodified', time()); if (preg_match("/\\.css\$/i", $tpl['file'])) { $tplfile->setVar('tpl_type', 'css'); } else { $tplfile->setVar('tpl_type', 'module'); } $tplfile->setVar('tpl_source', $tpldata, true); $tplfile->setVar('tpl_module', $dirname); $tplfile->setVar('tpl_tplset', 'default'); $tplfile->setVar('tpl_file', $tpl['file'], true); $tplfile->setVar('tpl_desc', $tpl['description'], true); if (!$tplfile_handler->insert($tplfile)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(__('Template %s could not be inserted!', 'rmcommon'), "<strong>" . $tpl['file'] . "</strong>") . '</span>'; } else { $newid = $tplfile->getVar('tpl_id'); $msgs[] = ' ' . sprintf(__('Template %s inserted to the database.', 'rmcommon'), "<strong>" . $tpl['file'] . "</strong>"); if ($xoopsConfig['template_set'] == 'default') { if (!xoops_template_touch($newid)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(__('ERROR: Could not recompile template %s', 'rmcommon'), "<strong>" . $tpl['file'] . "</strong>") . '</span>'; } else { $msgs[] = ' <span>' . sprintf(__('Template %s recompiled', 'rmcommon'), "<strong>" . $tpl['file'] . "</strong>") . '</span>'; } } } unset($tpldata); } else { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(__('ERROR: Could not delete old template %s. Aborting update of this file.', 'rmcommon'), "<strong>" . $tpl['file'] . "</strong>") . '</span>'; } } } $blocks = $module->getInfo('blocks'); $msgs[] = __('Rebuilding blocks...', 'rmcommon'); if ($blocks != false) { $showfuncs = array(); $funcfiles = array(); foreach ($blocks as $i => $block) { if (isset($block['show_func']) && $block['show_func'] != '' && isset($block['file']) && $block['file'] != '') { $editfunc = isset($block['edit_func']) ? $block['edit_func'] : ''; $showfuncs[] = $block['show_func']; $funcfiles[] = $block['file']; $template = ''; if (isset($block['template']) && trim($block['template']) != '') { $content = xoops_module_gettemplate($dirname, $block['template'], 'blocks'); } if (!$content) { $content = ''; } else { $template = $block['template']; } $options = ''; if (!empty($block['options'])) { $options = $block['options']; } $sql = "SELECT bid, name FROM " . $xoopsDB->prefix('newblocks') . " WHERE mid=" . $module->getVar('mid') . " AND func_num=" . $i . " AND show_func='" . addslashes($block['show_func']) . "' AND func_file='" . addslashes($block['file']) . "'"; $fresult = $xoopsDB->query($sql); $fcount = 0; while ($fblock = $xoopsDB->fetchArray($fresult)) { $fcount++; $sql = "UPDATE " . $xoopsDB->prefix("newblocks") . " SET name='" . addslashes($block['name']) . "', edit_func='" . addslashes($editfunc) . "', content='', template='" . $template . "', last_modified=" . time() . " WHERE bid=" . $fblock['bid']; $result = $xoopsDB->query($sql); if (!$result) { $msgs[] = " " . sprintf(__('ERROR: Could not update %s'), $fblock['name']); } else { $msgs[] = " " . sprintf(__('Block %s updated.', 'rmcommon'), $fblock['name']) . sprintf(__('Block ID: %s', 'rmcommon'), "<strong>" . $fblock['bid'] . "</strong>"); if ($template != '') { $tplfile = $tplfile_handler->find('default', 'block', $fblock['bid']); if (count($tplfile) == 0) { $tplfile_new =& $tplfile_handler->create(); $tplfile_new->setVar('tpl_module', $dirname); $tplfile_new->setVar('tpl_refid', $fblock['bid']); $tplfile_new->setVar('tpl_tplset', 'default'); $tplfile_new->setVar('tpl_file', $block['template'], true); $tplfile_new->setVar('tpl_type', 'block'); } else { $tplfile_new = $tplfile[0]; } $tplfile_new->setVar('tpl_source', $content, true); $tplfile_new->setVar('tpl_desc', $block['description'], true); $tplfile_new->setVar('tpl_lastmodified', time()); $tplfile_new->setVar('tpl_lastimported', 0); if (!$tplfile_handler->insert($tplfile_new)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(__('ERROR: Could not update %s template.', 'rmcommon'), "<strong>" . $block['template'] . "</strong>") . '</span>'; } else { $msgs[] = " " . sprintf(__('Template %s updated.', 'rmcommon'), "<strong>" . $block['template'] . "</strong>"); if ($xoopsConfig['template_set'] == 'default') { if (!xoops_template_touch($tplfile_new->getVar('tpl_id'))) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(__('ERROR: Could not recompile template %s', 'rmcommon'), "<strong>" . $block['template'] . "</strong>") . '</span>'; } else { $msgs[] = " " . sprintf(__('Template %s recompiled', 'rmcommon'), "<strong>" . $block['template'] . "</strong>"); } } } } } } if ($fcount == 0) { $newbid = $xoopsDB->genId($xoopsDB->prefix('newblocks') . '_bid_seq'); $block_name = addslashes($block['name']); $block_type = $module->getVar('dirname') == 'system' ? 'S' : 'M'; $sql = "INSERT INTO " . $xoopsDB->prefix("newblocks") . " (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, isactive, dirname, func_file, show_func, edit_func, template, last_modified) VALUES (" . $newbid . ", " . $module->getVar('mid') . ", " . $i . ",'" . addslashes($options) . "','" . $block_name . "', '" . $block_name . "', '', 0, 0, 0, '{$block_type}', 1, '" . addslashes($dirname) . "', '" . addslashes($block['file']) . "', '" . addslashes($block['show_func']) . "', '" . addslashes($editfunc) . "', '" . $template . "', " . time() . ")"; $result = $xoopsDB->query($sql); if (!$result) { $msgs[] = ' ' . sprintf(_('ERROR: Could not create %s', 'rmcommon'), $block['name']); $log .= $sql; } else { if (empty($newbid)) { $newbid = $xoopsDB->getInsertId(); } if ($module->getInfo('hasMain')) { $groups = array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS); } else { $groups = array(XOOPS_GROUP_ADMIN); } $gperm_handler =& xoops_gethandler('groupperm'); foreach ($groups as $mygroup) { $bperm =& $gperm_handler->create(); $bperm->setVar('gperm_groupid', $mygroup); $bperm->setVar('gperm_itemid', $newbid); $bperm->setVar('gperm_name', 'block_read'); $bperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($bperm)) { $msgs[] = ' <span style="color:#ff0000;">' . __('ERROR: Could not add block access right', 'rmcommon') . ' ' . sprintf(__("Block ID: %s", 'rmcommon'), "<strong>" . $newbid . "</strong>") . ' ' . sprintf(__('Group ID: %s', 'rmcommon'), "<strong>" . $mygroup . "</strong>") . '</span>'; } else { $msgs[] = ' ' . __('Added block access right', 'rmcommon') . ' ' . sprintf(__("Block ID: %s", 'rmcommon'), "<strong>" . $newbid . "</strong>") . ' ' . sprintf(__('Group ID: %s', 'rmcommon'), "<strong>" . $mygroup . "</strong>"); } } if ($template != '') { $tplfile =& $tplfile_handler->create(); $tplfile->setVar('tpl_module', $dirname); $tplfile->setVar('tpl_refid', $newbid); $tplfile->setVar('tpl_source', $content, true); $tplfile->setVar('tpl_tplset', 'default'); $tplfile->setVar('tpl_file', $block['template'], true); $tplfile->setVar('tpl_type', 'block'); $tplfile->setVar('tpl_lastimported', 0); $tplfile->setVar('tpl_lastmodified', time()); $tplfile->setVar('tpl_desc', $block['description'], true); if (!$tplfile_handler->insert($tplfile)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(__('ERROR: Could not insert template %s to the database.', 'rmcommon'), "<strong>" . $block['template'] . "</strong>") . '</span>'; } else { $newid = $tplfile->getVar('tpl_id'); $msgs[] = ' ' . sprintf(__('Template %s added to the database', 'rmcommon'), "<strong>" . $block['template'] . "</strong>"); if ($xoopsConfig['template_set'] == 'default') { if (!xoops_template_touch($newid)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(__('ERROR: Template %s recompile failed', 'rmcommon'), "<strong>" . $block['template'] . "</strong>") . '</span>'; } else { $msgs[] = ' ' . sprintf(__('Template %s recompiled', 'rmcommon'), "<strong>" . $block['template'] . "</strong>"); } } } } $msgs[] = ' ' . sprintf(__('Block %s created', 'rmcommon'), "<strong>" . $block['name'] . "</strong>") . sprintf(__("Block ID: %s", 'rmcommon'), "<strong>" . $newbid . "</strong>"); $sql = 'INSERT INTO ' . $xoopsDB->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)'; $xoopsDB->query($sql); } } } } $block_arr = XoopsBlock::getByModule($module->getVar('mid')); foreach ($block_arr as $block) { if (!in_array($block->getVar('show_func'), $showfuncs) || !in_array($block->getVar('func_file'), $funcfiles)) { $sql = sprintf("DELETE FROM %s WHERE bid = %u", $xoopsDB->prefix('newblocks'), $block->getVar('bid')); if (!$xoopsDB->query($sql)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(__('ERROR: Could not delete block %s', 'rmcommon'), "<strong>" . $block->getVar('name') . "</strong>") . sprintf(__("Block ID: %s", 'rmcommon'), "<strong>" . $block->getVar('bid') . "</strong>") . '</span>'; } else { $msgs[] = ' Block <strong>' . $block->getVar('name') . ' deleted. Block ID: <strong>' . $block->getVar('bid') . '</strong>'; if ($block->getVar('template') != '') { $tplfiles = $tplfile_handler->find(null, 'block', $block->getVar('bid')); if (is_array($tplfiles)) { $btcount = count($tplfiles); for ($k = 0; $k < $btcount; $k++) { if (!$tplfile_handler->delete($tplfiles[$k])) { $msgs[] = ' <span style="color:#ff0000;">' . __('ERROR: Could not remove deprecated block template.', 'rmcommon') . '(ID: <strong>' . $tplfiles[$k]->getVar('tpl_id') . '</strong>)</span>'; } else { $msgs[] = ' ' . sprintf(__('Block template %s deprecated', 'rmcommon'), "<strong>" . $tplfiles[$k]->getVar('tpl_file') . "</strong>"); } } } } } } } } // reset compile_id $xoopsTpl->setCompileId(); // first delete all config entries $config_handler =& xoops_gethandler('config'); $configs = $config_handler->getConfigs(new Criteria('conf_modid', $module->getVar('mid'))); $confcount = count($configs); $config_delng = array(); if ($confcount > 0) { $msgs[] = __('Deleting module config options...', 'rmcommon'); for ($i = 0; $i < $confcount; $i++) { if (!$config_handler->deleteConfig($configs[$i])) { $msgs[] = ' <span style="color:#ff0000;">' . __('ERROR: Could not delete config data from the database', 'rmcommon') . sprintf(__('Config ID: %s', 'rmcommon'), "<strong>" . $configs[$i]->getvar('conf_id') . "</strong>") . '</span>'; // save the name of config failed to delete for later use $config_delng[] = $configs[$i]->getvar('conf_name'); } else { $config_old[$configs[$i]->getvar('conf_name')]['value'] = $configs[$i]->getvar('conf_value', 'N'); $config_old[$configs[$i]->getvar('conf_name')]['formtype'] = $configs[$i]->getvar('conf_formtype'); $config_old[$configs[$i]->getvar('conf_name')]['valuetype'] = $configs[$i]->getvar('conf_valuetype'); $msgs[] = " " . __('Config data deleted from the database.', 'rmcommon') . ' ' . sprintf(__('Config ID: %s', 'rmcommon'), "<strong>" . $configs[$i]->getVar('conf_id') . "</strong>"); } } } // now reinsert them with the new settings $configs = $module->getInfo('config'); // Include if ($configs != false) { if ($module->getVar('hascomments') != 0) { include_once XOOPS_ROOT_PATH . '/include/comment_constants.php'; array_push($configs, array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN))); array_push($configs, array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0)); } } else { if ($module->getVar('hascomments') != 0) { $configs = array(); include_once XOOPS_ROOT_PATH . '/include/comment_constants.php'; $configs[] = array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN)); $configs[] = array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0); } } // RMV-NOTIFY if ($module->getVar('hasnotification') != 0) { if (empty($configs)) { $configs = array(); } // Main notification options include_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; include_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; $options = array(); $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE; $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK; $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE; $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH; //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1); $configs[] = array('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options' => $options); // Event specific notification options // FIXME: for some reason the default doesn't come up properly // initially is ok, but not when 'update' module.. $options = array(); $categories =& notificationCategoryInfo('', $module->getVar('mid')); foreach ($categories as $category) { $events =& notificationEvents($category['name'], false, $module->getVar('mid')); foreach ($events as $event) { if (!empty($event['invisible'])) { continue; } $option_name = $category['title'] . ' : ' . $event['title']; $option_value = $category['name'] . '-' . $event['name']; $options[$option_name] = $option_value; //$configs[] = array ('name' => notificationGenerateConfig($category,$event,'name'), 'title' => notificationGenerateConfig($category,$event,'title_constant'), 'description' => notificationGenerateConfig($category,$event,'description_constant'), 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1); } } $configs[] = array('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($options), 'options' => $options); } if ($configs != false) { $msgs[] = 'Adding module config data...'; $config_handler =& xoops_gethandler('config'); $order = 0; foreach ($configs as $config) { // only insert ones that have been deleted previously with success if (!in_array($config['name'], $config_delng)) { $confobj =& $config_handler->createConfig(); $confobj->setVar('conf_modid', $newmid); $confobj->setVar('conf_catid', 0); $confobj->setVar('conf_name', $config['name']); $confobj->setVar('conf_title', $config['title'], true); $confobj->setVar('conf_desc', $config['description'], true); $confobj->setVar('conf_formtype', $config['formtype']); $confobj->setVar('conf_valuetype', $config['valuetype']); if (isset($config_old[$config['name']]['value']) && $config_old[$config['name']]['formtype'] == $config['formtype'] && $config_old[$config['name']]['valuetype'] == $config['valuetype']) { // preserver the old value if any // form type and value type must be the same $confobj->setVar('conf_value', $config_old[$config['name']]['value'], true); } else { $confobj->setConfValueForInput($config['default'], true); //$confobj->setVar('conf_value', $config['default'], true); } $confobj->setVar('conf_order', $order); $confop_msgs = ''; if (isset($config['options']) && is_array($config['options'])) { foreach ($config['options'] as $key => $value) { $confop =& $config_handler->createConfigOption(); $confop->setVar('confop_name', $key, true); $confop->setVar('confop_value', $value, true); $confobj->setConfOptions($confop); $confop_msgs .= '<br /> ' . __('Config option added', 'rmcommon') . ' ' . __('Name:', 'rmcommon') . ' <strong>' . (defined($key) ? constant($key) : $key) . '</strong> ' . __('Value:', 'rmcommon') . ' <strong>' . $value . '</strong> '; unset($confop); } } $order++; if (false != $config_handler->insertConfig($confobj)) { //$msgs[] = ' Config <strong>'.$config['name'].'</strong> added to the database.'.$confop_msgs; $msgs[] = " " . sprintf(__('Config %s added to the database', 'rmcommon'), "<strong>" . $config['name'] . "</strong>") . $confop_msgs; } else { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(__('ERROR: Could not insert config %s to the database.', 'rmcommon'), "<strong>" . $config['name'] . "</strong>") . '</span>'; } unset($confobj); } } unset($configs); } // execute module specific update script if any $update_script = $module->getInfo('onUpdate'); if (false != $update_script && trim($update_script) != '') { include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($update_script); if (function_exists('xoops_module_update_' . $dirname)) { $func = 'xoops_module_update_' . $dirname; if (!$func($module, $prev_version)) { $msgs[] = "<p>" . sprintf(__('Failed to execute %s', 'rmcommon'), $func) . "</p>"; } else { $msgs[] = "<p>" . sprintf(__('%s executed successfully.', 'rmcommon'), "<strong>" . $func . "</strong>") . "</p>"; } } } foreach ($msgs as $msg) { $log .= $msg . '<br />'; } $log .= "<p>" . sprintf(__('Module %s updated successfully!', 'rmcommon'), "<strong>" . $module->getVar('name') . "</strong>") . "</p>"; } // Flush cache files for cpanel GUIs xoops_load("cpanel", "system"); XoopsSystemCpanel::flush(); return $log; }
$notification_handler->unsubscribe($category, $item_id, $event, $module_id, $user_id); } else { $notification_handler->subscribe($category, $item_id, $event); } } // TODO: something like grey box summary of actions (like multiple comment // deletion), with a button to return back... NOTE: we need some arguments // to help us get back to where we were... // TODO: finish integration with comments... i.e. need calls to // notifyUsers at appropriate places... (need to figure out where // comment submit occurs and where comment approval occurs)... include_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; $redirect_args = array(); foreach ($update_list as $update_item) { list($category, $item_id, $event) = split(',', $update_item['params']); $category_info =& notificationCategoryInfo($category); if (!empty($category_info['item_name'])) { $redirect_args[$category_info['item_name']] = $item_id; } } // TODO: write a central function to put together args with '?' and '&' // symbols... $argstring = ''; $first_arg = 1; foreach (array_keys($redirect_args) as $arg) { if ($first_arg) { $argstring .= "?" . $arg . "=" . $redirect_args[$arg]; $first_arg = 0; } else { $argstring .= "&" . $arg . "=" . $redirect_args[$arg]; }
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); } } } }