Пример #1
0
 public function userMenus()
 {
     $helper = Notifications::getInstance();
     $ret['name'] = $helper->getModule()->getVar('name');
     $ret['link'] = 'index.php';
     $ret['image'] = $helper->url('icons/logo_small.png');
     return $ret;
 }
Пример #2
0
function xoops_module_pre_uninstall_notifications(&$module)
{
    $xoops = Xoops::getInstance();
    XoopsLoad::loadFile($xoops->path('modules/notifications/class/helper.php'));
    $helper = Notifications::getInstance();
    $plugins = \Xoops\Module\Plugin::getPlugins('notifications');
    foreach (array_keys($plugins) as $dirname) {
        $helper->deleteModuleRelations($xoops->getModuleByDirname($dirname));
    }
    return true;
}
Пример #3
0
/**
 * @copyright       XOOPS Project (http://xoops.org)
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
 * @author          trabis <*****@*****.**>
 * @version         $Id$
 */
function b_notification_show()
{
    $xoops = Xoops::getInstance();
    $helper = Notifications::getInstance();
    include_once $helper->path('include/notification_functions.php');
    $helper->loadLanguage('main');
    // Notification must be enabled, and user must be logged in
    if (!$xoops->isUser() || !notificationEnabled('block')) {
        return false;
        // do not display block
    }
    $notification_handler = $helper->getHandlerNotification();
    // Now build the a nested associative array of info to pass
    // to the block template.
    $block = array();
    $categories = notificationSubscribableCategoryInfo();
    if (empty($categories)) {
        return false;
    }
    foreach ($categories as $category) {
        $section['name'] = $category['name'];
        $section['title'] = $category['title'];
        $section['description'] = $category['description'];
        $section['itemid'] = $category['item_id'];
        $section['events'] = array();
        $subscribed_events = $notification_handler->getSubscribedEvents($category['name'], $category['item_id'], $xoops->module->getVar('mid'), $xoops->user->getVar('uid'));
        foreach (notificationEvents($category['name'], true) as $event) {
            if (!empty($event['admin_only']) && !$xoops->user->isAdmin($xoops->module->getVar('mid'))) {
                continue;
            }
            $subscribed = in_array($event['name'], $subscribed_events) ? 1 : 0;
            $section['events'][$event['name']] = array('name' => $event['name'], 'title' => $event['title'], 'caption' => $event['caption'], 'description' => $event['description'], 'subscribed' => $subscribed);
        }
        $block['categories'][$category['name']] = $section;
    }
    // Additional form data
    $block['target_page'] = "notification_update.php";
    // FIXME: better or more standardized way to do this?
    $script_url = explode('/', $_SERVER['PHP_SELF']);
    $script_name = $script_url[count($script_url) - 1];
    $block['redirect_script'] = $script_name;
    $block['submit_button'] = _MD_NOTIFICATIONS_UPDATENOW;
    $block['notification_token'] = $xoops->security()->createToken();
    return $block;
}
Пример #4
0
         $error = '';
         foreach ($_REQUEST['memberslist_id'] as $del) {
             $del = (int) $del;
             $user = $member_handler->getUser($del);
             $groups = $user->getGroups();
             if (in_array(FixedGroups::ADMIN, $groups)) {
                 $error .= sprintf(SystemLocale::EF_CAN_NOT_DELETE_ADMIN_USER, $user->getVar("uname"));
                 $error .= '<br />';
             } elseif (!$member_handler->deleteUser($user)) {
                 $error .= sprintf(SystemLocale::EF_COULD_NOT_DELETE_USER, $user->getVar("uname"));
                 $error .= '<br />';
             } else {
                 $xoops->getHandlerOnline()->destroy($del);
                 // RMV-NOTIFY
                 if ($xoops->isActiveModule('notifications')) {
                     Notifications::getInstance()->getHandlerNotification()->unsubscribeByUser($del);
                 }
             }
         }
         if ($error != '') {
             $xoops->redirect("admin.php?fct=users", 3, sprintf(XoopsLocale::F_ERROR, $error));
         } else {
             $xoops->redirect("admin.php?fct=users", 1, XoopsLocale::S_DATABASE_UPDATED);
         }
     }
     break;
     // Save user
 // Save user
 case "users_save":
     if (isset($_REQUEST['uid'])) {
         //Update user
Пример #5
0
 public function displayPost()
 {
     $xoops = Xoops::getInstance();
     if (Request::getMethod() !== 'POST') {
         $xoops->redirect(\XoopsBaseConfig::get('url'), 1, XoopsLocale::E_NO_ACCESS_PERMISSION);
     }
     $id = Request::getInt('com_id');
     $modid = Request::getInt('com_modid');
     if (empty($modid)) {
         $xoops->redirect(\XoopsBaseConfig::get('url'), 1, XoopsLocale::E_NO_ACCESS_PERMISSION);
     }
     /* @var $comment CommentsComment */
     $comment = $this->getHandlerComment()->get($id);
     if (!is_object($comment)) {
         $xoops->redirect(\XoopsBaseConfig::get('url'), 1, XoopsLocale::E_NO_ACCESS_PERMISSION);
     }
     if (!$comment->isNew()) {
         $modid = $comment->getVar('modid');
     } else {
         $comment->setVar('modid', $modid);
     }
     $module = $xoops->getModuleById($modid);
     if (!is_object($module)) {
         $xoops->redirect(\XoopsBaseConfig::get('url'), 1, XoopsLocale::E_NO_ACCESS_PERMISSION);
     }
     $moddir = $module->getVar('dirname');
     if ($xoops->isAdminSide) {
         if (empty($id)) {
             $xoops->redirect(\XoopsBaseConfig::get('url'), 1, XoopsLocale::E_NO_ACCESS_PERMISSION);
         }
         $redirect_page = $this->url('admin/main.php?com_modid=' . $modid . '&amp;com_itemid');
     } else {
         if (COMMENTS_APPROVENONE == $xoops->getModuleConfig('com_rule', $module->getVar('dirname'))) {
             $xoops->redirect(\XoopsBaseConfig::get('url'), 1, XoopsLocale::E_NO_ACCESS_PERMISSION);
         }
         $redirect_page = '';
     }
     /* @var $plugin CommentsPluginInterface */
     if ($plugin = \Xoops\Module\Plugin::getPlugin($moddir, 'comments')) {
         if (!$xoops->isAdminSide) {
             $redirect_page = $xoops->url('modules/' . $moddir . '/' . $plugin->pageName() . '?');
             if (is_array($extraParams = $plugin->extraParams())) {
                 $extra_params = '';
                 foreach ($extraParams as $extra_param) {
                     $extra_params .= isset($_POST[$extra_param]) ? $extra_param . '=' . htmlspecialchars($_POST[$extra_param]) . '&amp;' : $extra_param . '=amp;';
                 }
                 $redirect_page .= $extra_params;
             }
             $redirect_page .= $plugin->itemName();
         }
         $comment_url = $redirect_page;
         $op = Request::getBool('com_dopost') ? 'post' : '';
         $op = Request::getBool('com_dopreview') ? 'preview' : $op;
         $op = Request::getBool('com_dodelete') ? 'delete' : $op;
         if ($op === 'preview' || $op === 'post') {
             if (!$xoops->security()->check()) {
                 $op = '';
             }
         }
         if ($op === 'post' && !$xoops->isUser()) {
             $xoopsCaptcha = XoopsCaptcha::getInstance();
             if (!$xoopsCaptcha->verify()) {
                 $captcha_message = $xoopsCaptcha->getMessage();
                 $op = 'preview';
             }
         }
         $title = XoopsLocale::trim(Request::getString('com_title'));
         $text = XoopsLocale::trim(Request::getString('com_text'));
         $mode = XoopsLocale::trim(Request::getString('com_mode', 'flat'));
         $order = XoopsLocale::trim(Request::getString('com_order', COMMENTS_OLD1ST));
         $itemid = Request::getInt('com_itemid');
         $pid = Request::getInt('com_pid');
         $rootid = Request::getInt('com_rootid');
         $status = Request::getInt('com_status');
         $dosmiley = Request::getBool('com_dosmiley');
         $doxcode = Request::getBool('com_doxcode');
         $dobr = Request::getBool('com_dobr');
         $dohtml = Request::getBool('com_html');
         $doimage = Request::getBool('com_doimage');
         $icon = XoopsLocale::trim(Request::getString('com_icon'));
         $comment->setVar('title', $title);
         $comment->setVar('text', $text);
         $comment->setVar('itemid', $itemid);
         $comment->setVar('pid', $pid);
         $comment->setVar('rootid', $rootid);
         $comment->setVar('status', $status);
         $comment->setVar('dosmiley', $dosmiley);
         $comment->setVar('doxcode', $doxcode);
         $comment->setVar('dobr', $dobr);
         $comment->setVar('dohtml', $dohtml);
         $comment->setVar('doimage', $doimage);
         $comment->setVar('icon', $icon);
         switch ($op) {
             case "delete":
                 $this->displayDelete();
                 break;
             case "preview":
                 $comment->setVar('doimage', 1);
                 if ($comment->getVar('dohtml') != 0) {
                     if ($xoops->isUser()) {
                         if (!$xoops->user->isAdmin($comment->getVar('modid'))) {
                             $comment->setVar('dohtml', 0);
                         }
                     } else {
                         $comment->setVar('dohtml', 0);
                     }
                 }
                 $xoops->header();
                 if (!$xoops->isAdminSide && !empty($captcha_message)) {
                     echo $xoops->alert('error', $captcha_message);
                 }
                 echo $this->renderHeader($comment->getVar('title', 'p'), $comment->getVar('text', 'p'), false, time());
                 $this->displayCommentForm($comment);
                 $xoops->footer();
                 break;
             case "post":
                 $comment->setVar('doimage', 1);
                 $comment_handler = $this->getHandlerComment();
                 $add_userpost = false;
                 $call_approvefunc = false;
                 $call_updatefunc = false;
                 // RMV-NOTIFY - this can be set to 'comment' or 'comment_submit'
                 $notify_event = false;
                 if (!empty($id)) {
                     $accesserror = false;
                     if ($xoops->isUser()) {
                         if ($xoops->user->isAdmin($comment->getVar('modid'))) {
                             if (!empty($status) && $status != COMMENTS_PENDING) {
                                 $old_status = $comment->getVar('status');
                                 $comment->setVar('status', $status);
                                 // if changing status from pending state, increment user post
                                 if (COMMENTS_PENDING == $old_status) {
                                     $add_userpost = true;
                                     if (COMMENTS_ACTIVE == $status) {
                                         $call_updatefunc = true;
                                         $call_approvefunc = true;
                                         // RMV-NOTIFY
                                         $notify_event = 'comment';
                                     }
                                 } else {
                                     if (COMMENTS_HIDDEN == $old_status && COMMENTS_ACTIVE == $status) {
                                         $call_updatefunc = true;
                                         // Comments can not be directly posted hidden,
                                         // no need to send notification here
                                     } else {
                                         if (COMMENTS_ACTIVE == $old_status && COMMENTS_HIDDEN == $status) {
                                             $call_updatefunc = true;
                                         }
                                     }
                                 }
                             }
                         } else {
                             $comment->setVar('dohtml', 0);
                             if ($comment->getVar('uid') != $xoops->user->getVar('uid')) {
                                 $accesserror = true;
                             }
                         }
                     } else {
                         $comment->setVar('dohtml', 0);
                         $accesserror = true;
                     }
                     if (false != $accesserror) {
                         $xoops->redirect($redirect_page . '=' . $comment->getVar('itemid') . '&amp;com_id=' . $comment->getVar('id') . '&amp;com_mode=' . $mode . '&amp;com_order=' . $order, 1, XoopsLocale::E_NO_ACCESS_PERMISSION);
                     }
                 } else {
                     $comment->setVar('created', time());
                     $comment->setVar('ip', $xoops->getEnv('REMOTE_ADDR'));
                     if ($xoops->isUser()) {
                         if ($xoops->user->isAdmin($comment->getVar('modid'))) {
                             $comment->setVar('status', COMMENTS_ACTIVE);
                             $add_userpost = true;
                             $call_approvefunc = true;
                             $call_updatefunc = true;
                             // RMV-NOTIFY
                             $notify_event = 'comment';
                         } else {
                             $comment->setVar('dohtml', 0);
                             switch ($xoops->getModuleConfig('com_rule')) {
                                 case COMMENTS_APPROVEALL:
                                 case COMMENTS_APPROVEUSER:
                                     $comment->setVar('status', COMMENTS_ACTIVE);
                                     $add_userpost = true;
                                     $call_approvefunc = true;
                                     $call_updatefunc = true;
                                     // RMV-NOTIFY
                                     $notify_event = 'comment';
                                     break;
                                 case COMMENTS_APPROVEADMIN:
                                 default:
                                     $comment->setVar('status', COMMENTS_PENDING);
                                     $notify_event = 'comment_submit';
                                     break;
                             }
                         }
                         if ($xoops->getModuleConfig('com_anonpost', $module->getVar('dirname')) && $comment->getVar('noname')) {
                             $comment->setVar('uid', 0);
                         } else {
                             $comment->setVar('uid', $xoops->user->getVar('uid'));
                         }
                     } else {
                         $comment->setVar('dohtml', 0);
                         $comment->setVar('uid', 0);
                         if ($xoops->getModuleConfig('com_anonpost', $module->getVar('dirname')) != 1) {
                             $xoops->redirect($redirect_page . '=' . $comment->getVar('itemid') . '&amp;com_id=' . $comment->getVar('id') . '&amp;com_mode=' . $mode . '&amp;com_order=' . $order, 1, XoopsLocale::E_NO_ACCESS_PERMISSION);
                         }
                     }
                     if ($comment->getVar('uid') == 0) {
                         switch ($xoops->getModuleConfig('com_rule')) {
                             case COMMENTS_APPROVEALL:
                                 $comment->setVar('status', COMMENTS_ACTIVE);
                                 $add_userpost = true;
                                 $call_approvefunc = true;
                                 $call_updatefunc = true;
                                 // RMV-NOTIFY
                                 $notify_event = 'comment';
                                 break;
                             case COMMENTS_APPROVEADMIN:
                             case COMMENTS_APPROVEUSER:
                             default:
                                 $comment->setVar('status', COMMENTS_PENDING);
                                 // RMV-NOTIFY
                                 $notify_event = 'comment_submit';
                                 break;
                         }
                     }
                 }
                 if ($comment->getVar('title') == '') {
                     $comment->setVar('title', XoopsLocale::NO_TITLE);
                 }
                 $comment->setVar('modified', time());
                 if (isset($extra_params)) {
                     $comment->setVar('exparams', $extra_params);
                 }
                 if (false != $comment_handler->insert($comment)) {
                     $newcid = $comment->getVar('id');
                     // set own id as root id if this is a top comment
                     if ($comment->getVar('rootid') == 0) {
                         $comment->setVar('rootid', $newcid);
                         if (!$comment_handler->updateByField($comment, 'rootid', $comment->getVar('rootid'))) {
                             $comment_handler->delete($comment);
                             $xoops->header();
                             echo $xoops->alert('error', $comment->getHtmlErrors());
                             $xoops->footer();
                         }
                     }
                     // call custom approve function if any
                     if (false != $call_approvefunc) {
                         $plugin->approve($comment);
                     }
                     if (false != $call_updatefunc) {
                         $criteria = new CriteriaCompo(new Criteria('modid', $comment->getVar('modid')));
                         $criteria->add(new Criteria('itemid', $comment->getVar('itemid')));
                         $criteria->add(new Criteria('status', COMMENTS_ACTIVE));
                         $comment_count = $comment_handler->getCount($criteria);
                         $plugin->update($comment->getVar('itemid'), $comment_count);
                     }
                     // increment user post if needed
                     $uid = $comment->getVar('uid');
                     if ($uid > 0 && false != $add_userpost) {
                         $member_handler = $xoops->getHandlerMember();
                         $poster = $member_handler->getUser($uid);
                         if ($poster instanceof XoopsUser) {
                             $member_handler->updateUserByField($poster, 'posts', $poster->getVar('posts') + 1);
                         }
                     }
                     // RMV-NOTIFY
                     // trigger notification event if necessary
                     if ($notify_event && $xoops->isActiveModule('notifications')) {
                         $notifications = Notifications::getInstance();
                         $not_modid = $comment->getVar('modid');
                         $not_catinfo = $notifications->getCommentsCategory($module->getVar('dirname'));
                         $not_category = $not_catinfo['name'];
                         $not_itemid = $comment->getVar('itemid');
                         $not_event = $notify_event;
                         // Build an ABSOLUTE URL to view the comment.  Make sure we
                         // point to a viewable page (i.e. not the system administration
                         // module).
                         $comment_tags = array();
                         $comment_tags['X_COMMENT_URL'] = $comment_url . '=' . $comment->getVar('itemid') . '&amp;com_id=' . $comment->getVar('id') . '&amp;com_rootid=' . $comment->getVar('rootid') . '&amp;com_mode=' . $mode . '&amp;com_order=' . $order . '#comment' . $comment->getVar('id');
                         if ($xoops->isActiveModule('notifications')) {
                             Notifications::getInstance()->getHandlerNotification()->triggerEvent($not_category, $not_itemid, $not_event, $comment_tags, false, $not_modid);
                         }
                     }
                     if (!isset($comment_post_results)) {
                         // if the comment is active, redirect to posted comment
                         if ($comment->getVar('status') == COMMENTS_ACTIVE) {
                             $xoops->redirect($redirect_page . '=' . $comment->getVar('itemid') . '&amp;com_id=' . $comment->getVar('id') . '&amp;com_rootid=' . $comment->getVar('rootid') . '&amp;com_mode=' . $mode . '&amp;com_order=' . $order . '#comment' . $comment->getVar('id'), 1, _MD_COMMENTS_THANKSPOST);
                         } else {
                             // not active, so redirect to top comment page
                             $xoops->redirect($redirect_page . '=' . $comment->getVar('itemid') . '&amp;com_mode=' . $mode . '&amp;com_order=' . $order . '#comment' . $comment->getVar('id'), 1, _MD_COMMENTS_THANKSPOST);
                         }
                     }
                 } else {
                     if (!isset($purge_comment_post_results)) {
                         $xoops->header();
                         echo $xoops->alert('error', $comment->getHtmlErrors());
                         $xoops->footer();
                     } else {
                         $comment_post_results = $comment->getErrors();
                     }
                 }
                 break;
             default:
                 $xoops->redirect(\XoopsBaseConfig::get('url') . '/', 1, implode('<br />', $xoops->security()->getErrors()));
                 break;
         }
     }
 }
Пример #6
0
 /**
  * Get an array of info for all events (each event has associative array)
  * in the selected category of the selected module.
  *
  * @param string $category_name Category name
  * @param bool   $enabled_only  If true, return only enabled events
  * @param string $dirname       Dirname of the module (default current module)
  *
  * @return mixed
  */
 public function getEvents($category_name, $enabled_only, $dirname = null)
 {
     $xoops = Xoops::getInstance();
     $helper = Notifications::getInstance();
     if (!isset($dirname)) {
         $dirname = $xoops->isModule() ? $xoops->module->getVar('dirname') : '';
     }
     /* @var $plugin NotificationsPluginInterface */
     if ($plugin = \Xoops\Module\Plugin::getPlugin($dirname, 'notifications')) {
         $events = $plugin->events();
         $category = $this->getCategory($category_name, $dirname);
         $event_array = array();
         $override_comment = false;
         $override_commentsubmit = false;
         $override_bookmark = false;
         foreach ($events as $event) {
             if ($event['category'] == $category_name) {
                 if (!is_dir($dir = \XoopsBaseConfig::get('root-path') . '/modules/' . $dirname . '/locale/' . $xoops->getConfig('locale') . '/templates/')) {
                     $dir = \XoopsBaseConfig::get('root-path') . '/modules/' . $dirname . '/locale/en_US/templates/';
                 }
                 $event['mail_template_dir'] = $dir;
                 if (!$enabled_only || $this->eventEnabled($category, $event, $dirname)) {
                     $event_array[] = $event;
                 }
                 if ($event['name'] === 'comment') {
                     $override_comment = true;
                 }
                 if ($event['name'] === 'comment_submit') {
                     $override_commentsubmit = true;
                 }
                 if ($event['name'] === 'bookmark') {
                     $override_bookmark = true;
                 }
             }
         }
         $helper->loadLanguage('main');
         // Insert comment info if applicable
         /* @var $commentsPlugin CommentsPluginInterface */
         if ($xoops->isActiveModule('comments') && ($commentsPlugin = \Xoops\Module\Plugin::getPlugin($dirname, 'comments'))) {
             //todo replace this
             if (!empty($category['item_name']) && $category['item_name'] == $commentsPlugin->itemName()) {
                 if (!is_dir($dir = \XoopsBaseConfig::get('root-path') . '/locale/' . $xoops->getConfig('locale') . '/templates/')) {
                     $dir = \XoopsBaseConfig::get('root-path') . '/locale/en_US/templates/';
                 }
                 $mail_template_dir = $dir;
                 $com_config = $xoops->getModuleConfigs($dirname);
                 if (!$enabled_only) {
                     $insert_comment = true;
                     $insert_submit = true;
                 } else {
                     $insert_comment = false;
                     $insert_submit = false;
                     switch ($com_config['com_rule']) {
                         case COMMENTS_APPROVENONE:
                             // comments disabled, no comment events
                             break;
                         case COMMENTS_APPROVEALL:
                             // all comments are automatically approved, no 'submit'
                             if (!$override_comment) {
                                 $insert_comment = true;
                             }
                             break;
                         case COMMENTS_APPROVEUSER:
                         case COMMENTS_APPROVEADMIN:
                             // comments first submitted, require later approval
                             if (!$override_comment) {
                                 $insert_comment = true;
                             }
                             if (!$override_commentsubmit) {
                                 $insert_submit = true;
                             }
                             break;
                     }
                 }
                 if ($insert_comment) {
                     $event = array('name' => 'comment', 'category' => $category['name'], 'title' => _MD_NOTIFICATIONS_COMMENT_NOTIFY, 'caption' => _MD_NOTIFICATIONS_COMMENT_NOTIFYCAP, 'description' => _MD_NOTIFICATIONS_COMMENT_NOTIFYDSC, 'mail_template_dir' => $mail_template_dir, 'mail_template' => 'comment_notify', 'mail_subject' => _MD_NOTIFICATIONS_COMMENT_NOTIFYSBJ);
                     if (!$enabled_only || $this->eventEnabled($category, $event, $dirname)) {
                         $event_array[] = $event;
                     }
                 }
                 if ($insert_submit) {
                     $event = array('name' => 'comment_submit', 'category' => $category['name'], 'title' => _MD_NOTIFICATIONS_COMMENTSUBMIT_NOTIFY, 'caption' => _MD_NOTIFICATIONS_COMMENTSUBMIT_NOTIFYCAP, 'description' => _MD_NOTIFICATIONS_COMMENTSUBMIT_NOTIFYDSC, 'mail_template_dir' => $mail_template_dir, 'mail_template' => 'commentsubmit_notify', 'mail_subject' => _MD_NOTIFICATIONS_COMMENTSUBMIT_NOTIFYSBJ, 'admin_only' => 1);
                     if (!$enabled_only || $this->eventEnabled($category, $event, $dirname)) {
                         $event_array[] = $event;
                     }
                 }
             }
         }
         // Insert bookmark info if appropriate
         if (!empty($category['allow_bookmark'])) {
             if (!$override_bookmark) {
                 $event = array('name' => 'bookmark', 'category' => $category['name'], 'title' => _MD_NOTIFICATIONS_BOOKMARK_NOTIFY, 'caption' => _MD_NOTIFICATIONS_BOOKMARK_NOTIFYCAP, 'description' => _MD_NOTIFICATIONS_BOOKMARK_NOTIFYDSC);
                 if (!$enabled_only || $this->eventEnabled($category, $event, $dirname)) {
                     $event_array[] = $event;
                 }
             }
         }
         return $event_array;
     }
     return array();
 }
Пример #7
0
 /**
  * core.include.checklogin.success
  *
  * @return void
  */
 public static function eventCoreIncludeCheckloginSuccess()
 {
     // This was in include checklogin.php, moving here for now
     // RMV-NOTIFY
     // Perform some maintenance of notification records
     $xoops = Xoops::getInstance();
     if ($xoops->user instanceof XoopsUser) {
         Notifications::getInstance()->getHandlerNotification()->doLoginMaintenance($xoops->user->getVar('uid'));
     }
 }
Пример #8
0
         $error_message .= PageLocale::E_WEIGHT . '<br />';
         $obj->setVar('content_weight', 0);
     } else {
         $obj->setVar('content_weight', Request::getInt('content_weight', 0));
     }
     if ($error == true) {
         $xoops->tpl()->assign('error_message', $error_message);
     } else {
         if ($newcontent_id = $content_Handler->insert($obj)) {
             // update permissions
             $perm_id = $content_id > 0 ? $content_id : $newcontent_id;
             $groups_view_item = Request::getArray('groups_view_item', array());
             $gperm_Handler->updatePerms($perm_id, $groups_view_item);
             //notifications
             if ($content_id == 0 && $xoops->isActiveModule('notifications')) {
                 $notification_handler = Notifications::getInstance()->getHandlerNotification();
                 $tags = array();
                 $tags['MODULE_NAME'] = 'page';
                 $tags['ITEM_NAME'] = Request::getString('content_title', '');
                 $tags['ITEM_URL'] = \XoopsBaseConfig::get('url') . '/modules/page/viewpage.php?id=' . $newcontent_id;
                 $notification_handler->triggerEvent('global', 0, 'newcontent', $tags);
                 $notification_handler->triggerEvent('item', $newcontent_id, 'newcontent', $tags);
             }
             $xoops->redirect('content.php', 2, XoopsLocale::S_DATABASE_UPDATED);
         }
         echo $xoops->alert('error', $obj->getHtmlErrors());
     }
     $form = $helper->getForm($obj, 'page_content');
     $xoops->tpl()->assign('form', $form->render());
     break;
 case 'delete':
Пример #9
0
 /**
  * triggerEvent
  *
  * @param int   $category     notification category
  * @param int   $item_id      ID of the item
  * @param int   $event        notification event
  * @param array $extra_tags   array of substitutions for template
  * @param array $user_list    users to notify
  * @param int   $module_id    module
  * @param int   $omit_user_id users to not notify
  *
  * @return bool
  */
 public function triggerEvent($category, $item_id, $event, $extra_tags = array(), $user_list = array(), $module_id = null, $omit_user_id = null)
 {
     $xoops = xoops::getInstance();
     $helper = Notifications::getInstance();
     if (!isset($module_id)) {
         $module = $xoops->module;
         $module_id = $xoops->isModule() ? $xoops->module->getVar('mid') : 0;
     } else {
         $module = $xoops->getHandlerModule()->get($module_id);
     }
     // Check if event is enabled
     $mod_config = $xoops->getHandlerConfig()->getConfigsByModule($module->getVar('mid'));
     if (empty($mod_config['notifications_enabled'])) {
         return false;
     }
     $category_info = $helper->getCategory($category, $module->getVar('dirname'));
     $event_info = $helper->getEvent($category, $event, $module->getVar('dirname'));
     if (!in_array($helper->generateConfig($category_info, $event_info, 'option_name'), $mod_config['notification_events']) && empty($event_info['invisible'])) {
         return false;
     }
     if (!isset($omit_user_id)) {
         if ($xoops->isUser()) {
             $omit_user_id = $xoops->user->getVar('uid');
         } else {
             $omit_user_id = 0;
         }
     }
     $criteria = new CriteriaCompo();
     $criteria->add(new Criteria('modid', (int) $module_id));
     $criteria->add(new Criteria('category', $category));
     $criteria->add(new Criteria('itemid', (int) $item_id));
     $criteria->add(new Criteria('event', $event));
     $mode_criteria = new CriteriaCompo();
     $mode_criteria->add(new Criteria('mode', NOTIFICATIONS_MODE_SENDALWAYS), 'OR');
     $mode_criteria->add(new Criteria('mode', NOTIFICATIONS_MODE_SENDONCETHENDELETE), 'OR');
     $mode_criteria->add(new Criteria('mode', NOTIFICATIONS_MODE_SENDONCETHENWAIT), 'OR');
     $criteria->add($mode_criteria);
     if (!empty($user_list)) {
         $user_criteria = new CriteriaCompo();
         foreach ($user_list as $user) {
             $user_criteria->add(new Criteria('uid', (int) $user), 'OR');
         }
         $criteria->add($user_criteria);
     }
     $notifications = $this->getObjectsArray($criteria);
     if (empty($notifications)) {
         return false;
     }
     $item_info = $helper->getEvent($category, $item_id, $module->getVar('dirname'));
     // Add some tag substitutions here
     $tags = $helper->getTags($category, $item_id, $event, $module->getVar('dirname'));
     $tags['X_ITEM_NAME'] = !empty($item_info['name']) ? $item_info['name'] : '[' . _MD_NOTIFICATIONS_ITEMNAMENOTAVAILABLE . ']';
     $tags['X_ITEM_URL'] = !empty($item_info['url']) ? $item_info['url'] : '[' . _MD_NOTIFICATIONS_ITEMURLNOTAVAILABLE . ']';
     $tags['X_ITEM_TYPE'] = !empty($category_info['item_name']) ? $category_info['title'] : '[' . _MD_NOTIFICATIONS_ITEMTYPENOTAVAILABLE . ']';
     $tags['X_MODULE'] = $module->getVar('name');
     $tags['X_MODULE_URL'] = \XoopsBaseConfig::get('url') . '/modules/' . $module->getVar('dirname') . '/';
     $tags['X_NOTIFY_CATEGORY'] = $category;
     $tags['X_NOTIFY_EVENT'] = $event;
     $template_dir = $event_info['mail_template_dir'];
     $template = $event_info['mail_template'] . '.tpl';
     $subject = $event_info['mail_subject'];
     foreach ($notifications as $notification) {
         /* @var $notification NotificationsNotification */
         if (empty($omit_user_id) || $notification->getVar('uid') != $omit_user_id) {
             // user-specific tags
             //$tags['X_UNSUBSCRIBE_URL'] = 'TODO';
             // TODO: don't show unsubscribe link if it is 'one-time' ??
             $tags['X_UNSUBSCRIBE_URL'] = $helper->url('index.php');
             $tags = array_merge($tags, $extra_tags);
             $notification->notifyUser($template_dir, $template, $subject, $tags);
         }
     }
     return true;
 }
Пример #10
0
 /**
  * Send notifications
  */
 public function sendNotifications()
 {
     $xoops = Xoops::getInstance();
     if ($xoops->isActiveModule('notifications')) {
         $tags = array();
         $tags['MODULE_NAME'] = $this->publisher->getModule()->getVar('name');
         $tags['CATEGORY_NAME'] = $this->getVar('name');
         $tags['CATEGORY_URL'] = $this->getCategoryUrl();
         $notification_handler = Notifications::getInstance()->getHandlerNotification();
         $notification_handler->triggerEvent('global', 0, 'category_created', $tags);
     }
 }
Пример #11
0
 /**
  * @param array $notifications
  */
 public function sendNotifications($notifications = array())
 {
     $xoops = Xoops::getInstance();
     if ($xoops->isActiveModule('notifications')) {
         $notification_handler = Notifications::getInstance()->getHandlerNotification();
         $tags = array();
         $tags['MODULE_NAME'] = $this->publisher->getModule()->getVar('name');
         $tags['ITEM_NAME'] = $this->title();
         $tags['CATEGORY_NAME'] = $this->getCategoryName();
         $tags['CATEGORY_URL'] = PUBLISHER_URL . '/category.php?categoryid=' . $this->getVar('categoryid');
         $tags['ITEM_BODY'] = $this->body();
         $tags['DATESUB'] = $this->datesub();
         foreach ($notifications as $notification) {
             switch ($notification) {
                 case _PUBLISHER_NOT_ITEM_PUBLISHED:
                     $tags['ITEM_URL'] = PUBLISHER_URL . '/item.php?itemid=' . $this->getVar('itemid');
                     $notification_handler->triggerEvent('global', 0, 'published', $tags, array(), $this->publisher->getModule()->getVar('mid'));
                     $notification_handler->triggerEvent('category', $this->getVar('categoryid'), 'published', $tags, array(), $this->publisher->getModule()->getVar('mid'));
                     $notification_handler->triggerEvent('item', $this->getVar('itemid'), 'approved', $tags, array(), $this->publisher->getModule()->getVar('mid'));
                     break;
                 case _PUBLISHER_NOT_ITEM_SUBMITTED:
                     $tags['WAITINGFILES_URL'] = PUBLISHER_URL . '/admin/item.php?itemid=' . $this->getVar('itemid');
                     $notification_handler->triggerEvent('global', 0, 'submitted', $tags, array(), $this->publisher->getModule()->getVar('mid'));
                     $notification_handler->triggerEvent('category', $this->getVar('categoryid'), 'submitted', $tags, array(), $this->publisher->getModule()->getVar('mid'));
                     break;
                 case _PUBLISHER_NOT_ITEM_REJECTED:
                     $notification_handler->triggerEvent('item', $this->getVar('itemid'), 'rejected', $tags, array(), $this->publisher->getModule()->getVar('mid'));
                     break;
                 case -1:
                 default:
                     break;
             }
         }
     }
 }
Пример #12
0
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
 * XOOPS notification
 *
 * @copyright       XOOPS Project (http://xoops.org)
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
 * @package         core
 * @since           2.0.0
 * @version         $Id$
 */
include dirname(dirname(__DIR__)) . '/mainfile.php';
$xoops = Xoops::getInstance();
$helper = Notifications::getInstance();
if (!$xoops->isUser()) {
    $xoops->redirect('index.php', 3, _MD_NOTIFICATIONS_NOACCESS);
}
$uid = $xoops->user->getVar('uid');
$op = 'list';
if (isset($_POST['op'])) {
    $op = trim($_POST['op']);
} else {
    if (isset($_GET['op'])) {
        $op = trim($_GET['op']);
    }
}
if (isset($_POST['delete'])) {
    $op = 'delete';
} else {