Пример #1
0
/**
 * Enable notifications for a member on a notification type+category.
 *
 * @param  ID_TEXT		The notification code to use
 * @param  ?SHORT_TEXT	The category within the notification code (NULL: none)
 * @param  ?MEMBER		The member being signed up (NULL: current member)
 * @param  ?integer		Setting to use (NULL: default)
 */
function enable_notifications($notification_code, $notification_category, $member_id = NULL, $setting = NULL)
{
    if (is_null($member_id)) {
        $member_id = get_member();
    }
    if (is_guest($member_id)) {
        return;
    }
    if (is_null($setting)) {
        $ob = _get_notification_ob_for_code($notification_code);
        if (is_null($ob)) {
            warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
        }
        $setting = $ob->get_default_auto_setting($notification_code, $notification_category);
        if (!_notification_setting_available($setting, $member_id)) {
            $setting = _find_member_statistical_notification_type($member_id);
        }
    }
    $db = substr($notification_code, 0, 4) == 'ocf_' ? $GLOBALS['FORUM_DB'] : $GLOBALS['SITE_DB'];
    $db->query_delete('notifications_enabled', array('l_member_id' => $member_id, 'l_notification_code' => substr($notification_code, 0, 80), 'l_code_category' => is_null($notification_category) ? '' : $notification_category));
    $db->query_insert('notifications_enabled', array('l_member_id' => $member_id, 'l_notification_code' => substr($notification_code, 0, 80), 'l_code_category' => is_null($notification_category) ? '' : $notification_category, 'l_setting' => $setting));
    if ($notification_code == 'comment_posted' && get_forum_type() == 'ocf') {
        $topic_id = $GLOBALS['FORUM_DRIVER']->find_topic_id_for_topic_identifier(get_option('comments_forum_name'), $notification_category);
        if (!is_null($topic_id)) {
            enable_notifications('ocf_topic', strval($topic_id), $member_id);
        }
    }
    global $NOTIFICATION_SETTING_CACHE;
    $NOTIFICATION_SETTING_CACHE = array();
}
Пример #2
0
/**
 * Build a tree UI for all categories available.
 *
 * @param  array			Notification types
 * @param  ID_TEXT		The notification code to work with
 * @param  object			Notificiation hook object
 * @param  ?ID_TEXT		Category we're looking under (NULL: root)
 * @param  integer		Recursion depth
 * @return tempcode		UI
 */
function _notifications_build_category_tree($_notification_types, $notification_code, $ob, $id, $depth = 0)
{
    static $done_get_change = false;
    $_notification_categories = $ob->create_category_tree($notification_code, $id);
    $statistical_notification_type = _find_member_statistical_notification_type(get_member());
    $notification_categories = array();
    foreach ($_notification_categories as $c) {
        $notification_category = is_integer($c['id']) ? strval($c['id']) : $c['id'];
        $current_setting = notifications_setting($notification_code, $notification_category);
        if ($current_setting == A__STATISTICAL) {
            $current_setting = _find_member_statistical_notification_type(get_member());
        }
        $notification_types = array();
        foreach ($_notification_types as $possible => $ntype) {
            $current_setting = notifications_setting($notification_code, $notification_category);
            if ($current_setting == A__STATISTICAL) {
                $current_setting = $statistical_notification_type;
            }
            $allowed_setting = $ob->allowed_settings($notification_code);
            $available = ($possible & $allowed_setting) != 0;
            if (count($_POST) != 0) {
                $checked = post_param_integer('notification_' . $notification_category . '_' . $ntype, 0);
            } else {
                $checked = ($possible & $current_setting) != 0 ? 1 : 0;
            }
            $notification_types[] = array('NTYPE' => $ntype, 'LABEL' => do_lang_tempcode('ENABLE_NOTIFICATIONS_' . $ntype), 'CHECKED' => $checked == 1, 'RAW' => strval($possible), 'AVAILABLE' => $available, 'SCOPE' => $notification_category);
        }
        if (!array_key_exists('num_children', $c) && array_key_exists('child_count', $c)) {
            $c['num_children'] = $c['child_count'];
        }
        if (!array_key_exists('num_children', $c) && array_key_exists('children', $c)) {
            $c['num_children'] = count($c['children']);
        }
        $children = new ocp_tempcode();
        if (array_key_exists('num_children', $c) && $c['num_children'] != 0) {
            $children = _notifications_build_category_tree($_notification_types, $notification_code, $ob, $notification_category, $depth + 1);
        }
        $notification_categories[] = array('NUM_CHILDREN' => strval(array_key_exists('num_children', $c) ? $c['num_children'] : 0), 'DEPTH' => strval($depth), 'NOTIFICATION_CATEGORY' => $notification_category, 'NOTIFICATION_TYPES' => $notification_types, 'CATEGORY_TITLE' => $c['title'], 'CHECKED' => notifications_enabled($notification_code, $notification_category), 'CHILDREN' => $children);
    }
    $tree = do_template('NOTIFICATIONS_TREE', array('NOTIFICATION_CODE' => $notification_code, 'NOTIFICATION_CATEGORIES' => $notification_categories));
    return $tree;
}