Ejemplo n.º 1
0
function get_parent_list($value_id)
{
    $sql = tep_db_query("select parent_id from " . TABLE_EPF_VALUES . " where value_id = " . (int) $value_id);
    $value = tep_db_fetch_array($sql);
    if ($value['parent_id'] > 0) {
        return get_parent_list($value['parent_id']) . ',' . $value_id;
    } else {
        return $value_id;
    }
}
Ejemplo n.º 2
0
/**
 * Mark a particular forum as read.
 *
 * @param int The forum ID
 */
function mark_forum_read($fid)
{
    global $mybb, $db;
    // Can only do "true" tracking for registered users
    if ($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid']) {
        // Experimental setting to mark parent forums as read
        $forums_to_read = array();
        if ($mybb->settings['readparentforums']) {
            $ignored_forums = array();
            $forums = array_reverse(explode(",", get_parent_list($fid)));
            unset($forums[0]);
            if (!empty($forums)) {
                $ignored_forums[] = $fid;
                foreach ($forums as $forum) {
                    $fids = array($forum);
                    $ignored_forums[] = $forum;
                    $children = explode(",", get_parent_list($forum));
                    foreach ($children as $child) {
                        if (in_array($child, $ignored_forums)) {
                            continue;
                        }
                        $fids[] = $child;
                        $ignored_forums[] = $child;
                    }
                    if (fetch_unread_count(implode(",", $fids)) == 0) {
                        $forums_to_read[] = $forum;
                    }
                }
            }
        }
        switch ($db->type) {
            case "pgsql":
            case "sqlite":
                add_shutdown(array($db, "replace_query"), array("forumsread", array('fid' => $fid, 'uid' => $mybb->user['uid'], 'dateline' => TIME_NOW), array("fid", "uid")));
                if (!empty($forums_to_read)) {
                    foreach ($forums_to_read as $forum) {
                        add_shutdown(array($db, "replace_query"), array("forumsread", array('fid' => $forum, 'uid' => $mybb->user['uid'], 'dateline' => TIME_NOW), array('fid', 'uid')));
                    }
                }
                break;
            default:
                $child_sql = '';
                if (!empty($forums_to_read)) {
                    foreach ($forums_to_read as $forum) {
                        $child_sql .= ", ('{$forum}', '{$mybb->user['uid']}', '" . TIME_NOW . "')";
                    }
                }
                $db->shutdown_query("\n\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "forumsread (fid, uid, dateline)\n\t\t\t\t\tVALUES('{$fid}', '{$mybb->user['uid']}', '" . TIME_NOW . "'){$child_sql}\n\t\t\t\t");
        }
    } else {
        my_set_array_cookie("forumread", $fid, TIME_NOW, -1);
    }
}
Ejemplo n.º 3
0
 /**
  * Remove thread subscriptions (from one or multiple threads in the same forum)
  *
  * @param int|array $tids Thread ID, or an array of thread IDs from the same forum.
  * @param boolean $all True (default) to delete all subscriptions, false to only delete subscriptions from users with no permission to read the thread
  * @param int $fid (Only applies if $all is false) The forum ID of the thread
  * @return boolean
  */
 function remove_thread_subscriptions($tids, $all = true, $fid = 0)
 {
     global $db, $plugins;
     // Format thread IDs
     if (!is_array($tids)) {
         $tids = array($tids);
     }
     if (empty($tids)) {
         return false;
     }
     // Make sure we only have valid values
     $tids = array_map('intval', $tids);
     $fid = (int) $fid;
     $tids_csv = implode(',', $tids);
     // Delete only subscriptions from users who no longer have permission to read the thread.
     if (!$all) {
         // Get groups that cannot view the forum or its threads
         $forum_parentlist = get_parent_list($fid);
         $query = $db->simple_select("forumpermissions", "gid", "fid IN ({$forum_parentlist}) AND (canview=0 OR canviewthreads=0)");
         $groups = array();
         $additional_groups = '';
         while ($group = $db->fetch_array($query)) {
             $groups[] = $group['gid'];
             switch ($db->type) {
                 case "pgsql":
                 case "sqlite":
                     $additional_groups .= " OR ','||u.additionalgroups||',' LIKE ',{$group['gid']},'";
                     break;
                 default:
                     $additional_groups .= " OR CONCAT(',',u.additionalgroups,',') LIKE ',{$group['gid']},'";
             }
         }
         // If there are groups found, delete subscriptions from users in these groups
         if (count($groups) > 0) {
             $groups_csv = implode(',', $groups);
             $query = $db->query("\n\t\t\t\t\tSELECT s.tid, u.uid\n\t\t\t\t\tFROM " . TABLE_PREFIX . "threadsubscriptions s\n\t\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "users u ON (u.uid=s.uid)\n\t\t\t\t\tWHERE s.tid IN ({$tids_csv})\n\t\t\t\t\tAND (u.usergroup IN ({$groups_csv}){$additional_groups})\n\t\t\t\t");
             while ($subscription = $db->fetch_array($query)) {
                 $db->delete_query("threadsubscriptions", "uid='{$subscription['uid']}' AND tid='{$subscription['tid']}'");
             }
         }
     } else {
         $db->delete_query("threadsubscriptions", "tid IN ({$tids_csv})");
     }
     $arguments = array("tids" => $tids, "all" => $all, "fid" => $fid);
     $plugins->run_hooks("class_moderation_remove_thread_subscriptions", $arguments);
     return true;
 }
Ejemplo n.º 4
0
/**
 * Return the permissions for a moderator in a specific forum
 *
 * @param fid The forum ID
 * @param uid The user ID to fetch permissions for (0 assumes current logged in user)
 * @param string The parent list for the forum (if blank, will be fetched)
 * @return array Array of moderator permissions for the specific forum
 */
function get_moderator_permissions($fid, $uid = "0", $parentslist = "")
{
    global $mybb, $cache, $db;
    static $modpermscache;
    if ($uid < 1) {
        $uid = $mybb->user['uid'];
    }
    if ($uid == 0) {
        return false;
    }
    if (isset($modpermscache[$fid][$uid])) {
        return $modpermscache[$fid][$uid];
    }
    if (!$parentslist) {
        $parentslist = explode(',', get_parent_list($fid));
    }
    // Get user groups
    $perms = array();
    $user = get_user($uid);
    $groups = array($user['usergroup']);
    if (!empty($user['additionalgroups'])) {
        $extra_groups = explode(",", $user['additionalgroups']);
        foreach ($extra_groups as $extra_group) {
            $groups[] = $extra_group;
        }
    }
    $mod_cache = $cache->read("moderators");
    foreach ($mod_cache as $forumid => $forum) {
        if (!is_array($forum) || !in_array($forumid, $parentslist)) {
            // No perms or we're not after this forum
            continue;
        }
        // User settings override usergroup settings
        if (is_array($forum['users'][$uid])) {
            $perm = $forum['users'][$uid];
            foreach ($perm as $action => $value) {
                if (strpos($action, "can") === false) {
                    continue;
                }
                // Figure out the user permissions
                if ($value == 0) {
                    // The user doesn't have permission to set this action
                    $perms[$action] = 0;
                } else {
                    $perms[$action] = max($perm[$action], $perms[$action]);
                }
            }
        }
        foreach ($groups as $group) {
            if (!is_array($forum['usergroups'][$group])) {
                // There are no permissions set for this group
                continue;
            }
            $perm = $forum['usergroups'][$group];
            foreach ($perm as $action => $value) {
                if (strpos($action, "can") === false) {
                    continue;
                }
                $perms[$action] = max($perm[$action], $perms[$action]);
            }
        }
    }
    $modpermscache[$fid][$uid] = $perms;
    return $perms;
}
Ejemplo n.º 5
0
/**
 * Return the permissions for a moderator in a specific forum
 *
 * @param fid The forum ID
 * @param uid The user ID to fetch permissions for (0 assumes current logged in user)
 * @param string The parent list for the forum (if blank, will be fetched)
 * @return array Array of moderator permissions for the specific forum
 */
function get_moderator_permissions($fid, $uid = "0", $parentslist = "")
{
    global $mybb, $db;
    static $modpermscache;
    if ($uid < 1) {
        $uid = $mybb->user['uid'];
    }
    if ($uid == 0) {
        return false;
    }
    if (!isset($modpermscache[$fid][$uid])) {
        if (!$parentslist) {
            $parentslist = get_parent_list($fid);
        }
        $sql = build_parent_list($fid, "fid", "OR", $parentslist);
        $query = $db->simple_select("moderators", "*", "uid='{$uid}' AND {$sql}");
        $perms = $db->fetch_array($query);
        if (!$perms) {
            return false;
        }
        $modpermscache[$fid][$uid] = $perms;
    } else {
        $perms = $modpermscache[$fid][$uid];
    }
    return $perms;
}