Exemplo n.º 1
0
function sync($type, $id = false)
{
    global $db;
    switch ($type) {
        case 'all forums':
            $sql = "SELECT forum_id\n\t\t\t\tFROM " . FORUMS_TABLE;
            if (!($result = $db->sql_query($sql))) {
                message_die(GENERAL_ERROR, 'Could not get forum IDs', '', __LINE__, __FILE__, $sql);
            }
            while ($row = $db->sql_fetchrow($result)) {
                sync('forum', $row['forum_id']);
            }
            break;
        case 'all topics':
            $sql = "SELECT topic_id\n\t\t\t\tFROM " . TOPICS_TABLE;
            if (!($result = $db->sql_query($sql))) {
                message_die(GENERAL_ERROR, 'Could not get topic ID', '', __LINE__, __FILE__, $sql);
            }
            while ($row = $db->sql_fetchrow($result)) {
                sync('topic', $row['topic_id']);
            }
            break;
        case 'forum':
            $sql = "SELECT MAX(post_id) AS last_post, COUNT(post_id) AS total \n\t\t\t\tFROM " . POSTS_TABLE . "  \n\t\t\t\tWHERE forum_id = {$id}";
            if (!($result = $db->sql_query($sql))) {
                message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql);
            }
            if ($row = $db->sql_fetchrow($result)) {
                $last_post = $row['last_post'] ? $row['last_post'] : 0;
                $total_posts = $row['total'] ? $row['total'] : 0;
            } else {
                $last_post = 0;
                $total_posts = 0;
            }
            $sql = "SELECT COUNT(topic_id) AS total\n\t\t\t\tFROM " . TOPICS_TABLE . "\n\t\t\t\tWHERE forum_id = {$id}";
            if (!($result = $db->sql_query($sql))) {
                message_die(GENERAL_ERROR, 'Could not get topic count', '', __LINE__, __FILE__, $sql);
            }
            $total_topics = ($row = $db->sql_fetchrow($result)) ? $row['total'] ? $row['total'] : 0 : 0;
            $sql = "UPDATE " . FORUMS_TABLE . "\n\t\t\t\tSET forum_last_post_id = {$last_post}, forum_posts = {$total_posts}, forum_topics = {$total_topics}\n\t\t\t\tWHERE forum_id = {$id}";
            if (!$db->sql_query($sql)) {
                message_die(GENERAL_ERROR, 'Could not update forum', '', __LINE__, __FILE__, $sql);
            }
            break;
        case 'topic':
            $sql = "SELECT MAX(post_id) AS last_post, MIN(post_id) AS first_post, COUNT(post_id) AS total_posts\n\t\t\t\tFROM " . POSTS_TABLE . "\n\t\t\t\tWHERE topic_id = {$id}";
            if (!($result = $db->sql_query($sql))) {
                message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql);
            }
            if ($row = $db->sql_fetchrow($result)) {
                if ($row['total_posts']) {
                    // Correct the details of this topic
                    $sql = 'UPDATE ' . TOPICS_TABLE . ' 
						SET topic_replies = ' . ($row['total_posts'] - 1) . ', topic_first_post_id = ' . $row['first_post'] . ', topic_last_post_id = ' . $row['last_post'] . "\n\t\t\t\t\t\tWHERE topic_id = {$id}";
                    if (!$db->sql_query($sql)) {
                        message_die(GENERAL_ERROR, 'Could not update topic', '', __LINE__, __FILE__, $sql);
                    }
                } else {
                    // There are no replies to this topic
                    // Check if it is a move stub
                    $sql = 'SELECT topic_moved_id 
						FROM ' . TOPICS_TABLE . " \n\t\t\t\t\t\tWHERE topic_id = {$id}";
                    if (!($result = $db->sql_query($sql))) {
                        message_die(GENERAL_ERROR, 'Could not get topic ID', '', __LINE__, __FILE__, $sql);
                    }
                    if ($row = $db->sql_fetchrow($result)) {
                        if (!$row['topic_moved_id']) {
                            $sql = 'DELETE FROM ' . TOPICS_TABLE . " WHERE topic_id = {$id}";
                            if (!$db->sql_query($sql)) {
                                message_die(GENERAL_ERROR, 'Could not remove topic', '', __LINE__, __FILE__, $sql);
                            }
                        }
                    }
                    $db->sql_freeresult($result);
                }
            }
            attachment_sync_topic($id);
            break;
    }
    return true;
}
Exemplo n.º 2
0
}
if ($mode == 'sync') {
    $info = '';
    @set_time_limit(0);
    echo isset($lang['Sync_topics']) ? $lang['Sync_topics'] : 'Sync Topics';
    $sql = "SELECT topic_id FROM " . TOPICS_TABLE;
    $result = $db->sql_query($sql);
    echo '<br />';
    $i = 0;
    while ($row = $db->sql_fetchrow($result)) {
        @flush();
        echo '.';
        if ($i % 50 == 0) {
            echo '<br />';
        }
        attachment_sync_topic($row['topic_id']);
        $i++;
    }
    $db->sql_freeresult($result);
    echo '<br /><br />';
    echo isset($lang['Sync_posts']) ? $lang['Sync_posts'] : 'Sync Posts';
    // Reassign Attachments to the Poster ID
    $sql = 'SELECT a.attach_id, a.post_id, a.user_id_1, p.poster_id
		FROM ' . ATTACHMENTS_TABLE . ' a, ' . POSTS_TABLE . ' p
		WHERE a.user_id_2 = 0
			AND p.post_id = a.post_id
			AND a.user_id_1 <> p.poster_id';
    $result = $db->sql_query($sql);
    echo '<br />';
    $rows = $db->sql_fetchrowset($result);
    $num_rows = $db->sql_numrows($result);
Exemplo n.º 3
0
/**
* Delete Attachment(s) from post(s) (intern)
*/
function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, $user_id = 0)
{
    global $db;
    // Generate Array, if it's not an array
    if ($post_id_array === 0 && $attach_id_array === 0 && $page === 0) {
        return;
    }
    if ($post_id_array === 0 && $attach_id_array !== 0) {
        $post_id_array = array();
        if (!is_array($attach_id_array)) {
            if (strstr($attach_id_array, ', ')) {
                $attach_id_array = explode(', ', $attach_id_array);
            } else {
                if (strstr($attach_id_array, ',')) {
                    $attach_id_array = explode(',', $attach_id_array);
                } else {
                    $attach_id = intval($attach_id_array);
                    $attach_id_array = array();
                    $attach_id_array[] = $attach_id;
                }
            }
        }
        // Get the post_ids to fill the array
        if ($page == PAGE_PRIVMSGS) {
            $p_id = 'privmsgs_id';
        } else {
            $p_id = 'post_id';
        }
        $sql = "SELECT {$p_id} \n\t\t\tFROM " . ATTACHMENTS_TABLE . '
				WHERE attach_id IN (' . implode(', ', $attach_id_array) . ")\n\t\t\tGROUP BY {$p_id}";
        if (!($result = $db->sql_query($sql))) {
            message_die(GENERAL_ERROR, 'Could not select ids', '', __LINE__, __FILE__, $sql);
        }
        $num_post_list = $db->sql_numrows($result);
        if ($num_post_list == 0) {
            $db->sql_freeresult($result);
            return;
        }
        while ($row = $db->sql_fetchrow($result)) {
            $post_id_array[] = intval($row[$p_id]);
        }
        $db->sql_freeresult($result);
    }
    if (!is_array($post_id_array)) {
        if (trim($post_id_array) == '') {
            return;
        }
        if (strstr($post_id_array, ', ')) {
            $post_id_array = explode(', ', $post_id_array);
        } else {
            if (strstr($post_id_array, ',')) {
                $post_id_array = explode(',', $post_id_array);
            } else {
                $post_id = intval($post_id_array);
                $post_id_array = array();
                $post_id_array[] = $post_id;
            }
        }
    }
    if (!sizeof($post_id_array)) {
        return;
    }
    // First of all, determine the post id and attach_id
    if ($attach_id_array === 0) {
        $attach_id_array = array();
        // Get the attach_ids to fill the array
        if ($page == PAGE_PRIVMSGS) {
            $whereclause = 'WHERE privmsgs_id IN (' . implode(', ', $post_id_array) . ')';
        } else {
            $whereclause = 'WHERE post_id IN (' . implode(', ', $post_id_array) . ')';
        }
        $sql = 'SELECT attach_id 
			FROM ' . ATTACHMENTS_TABLE . " {$whereclause} \n\t\t\tGROUP BY attach_id";
        if (!($result = $db->sql_query($sql))) {
            message_die(GENERAL_ERROR, 'Could not select Attachment Ids', '', __LINE__, __FILE__, $sql);
        }
        $num_attach_list = $db->sql_numrows($result);
        if ($num_attach_list == 0) {
            $db->sql_freeresult($result);
            return;
        }
        while ($row = $db->sql_fetchrow($result)) {
            $attach_id_array[] = (int) $row['attach_id'];
        }
        $db->sql_freeresult($result);
    }
    if (!is_array($attach_id_array)) {
        if (strstr($attach_id_array, ', ')) {
            $attach_id_array = explode(', ', $attach_id_array);
        } else {
            if (strstr($attach_id_array, ',')) {
                $attach_id_array = explode(',', $attach_id_array);
            } else {
                $attach_id = intval($attach_id_array);
                $attach_id_array = array();
                $attach_id_array[] = $attach_id;
            }
        }
    }
    if (!sizeof($attach_id_array)) {
        return;
    }
    if ($page == PAGE_PRIVMSGS) {
        $sql_id = 'privmsgs_id';
        if ($user_id) {
            $post_id_array_2 = array();
            $sql = 'SELECT privmsgs_id, privmsgs_type, privmsgs_to_userid, privmsgs_from_userid
				FROM ' . PRIVMSGS_TABLE . '
				WHERE privmsgs_id IN (' . implode(', ', $post_id_array) . ')';
            if (!($result = $db->sql_query($sql))) {
                message_die(GENERAL_ERROR, 'Couldn\'t get Privmsgs Type', '', __LINE__, __FILE__, $sql);
            }
            while ($row = $db->sql_fetchrow($result)) {
                $privmsgs_type = $row['privmsgs_type'];
                if ($privmsgs_type == PRIVMSGS_READ_MAIL || $privmsgs_type == PRIVMSGS_NEW_MAIL || $privmsgs_type == PRIVMSGS_UNREAD_MAIL) {
                    if ($row['privmsgs_to_userid'] == $user_id) {
                        $post_id_array_2[] = $row['privmsgs_id'];
                    }
                } else {
                    if ($privmsgs_type == PRIVMSGS_SENT_MAIL) {
                        if ($row['privmsgs_from_userid'] == $user_id) {
                            $post_id_array_2[] = $row['privmsgs_id'];
                        }
                    } else {
                        if ($privmsgs_type == PRIVMSGS_SAVED_OUT_MAIL) {
                            if ($row['privmsgs_from_userid'] == $user_id) {
                                $post_id_array_2[] = $row['privmsgs_id'];
                            }
                        } else {
                            if ($privmsgs_type == PRIVMSGS_SAVED_IN_MAIL) {
                                if ($row['privmsgs_to_userid'] == $user_id) {
                                    $post_id_array_2[] = $row['privmsgs_id'];
                                }
                            }
                        }
                    }
                }
            }
            $db->sql_freeresult($result);
            $post_id_array = $post_id_array_2;
        }
    } else {
        $sql_id = 'post_id';
    }
    if (sizeof($post_id_array) && sizeof($attach_id_array)) {
        $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . ' 
			WHERE attach_id IN (' . implode(', ', $attach_id_array) . ") \n\t\t\t\tAND {$sql_id} IN (" . implode(', ', $post_id_array) . ')';
        if (!$db->sql_query($sql)) {
            message_die(GENERAL_ERROR, $lang['Error_deleted_attachments'], '', __LINE__, __FILE__, $sql);
        }
        for ($i = 0; $i < sizeof($attach_id_array); $i++) {
            $sql = 'SELECT attach_id 
				FROM ' . ATTACHMENTS_TABLE . ' 
					WHERE attach_id = ' . (int) $attach_id_array[$i];
            if (!($result = $db->sql_query($sql))) {
                message_die(GENERAL_ERROR, 'Could not select Attachment Ids', '', __LINE__, __FILE__, $sql);
            }
            $num_rows = $db->sql_numrows($result);
            $db->sql_freeresult($result);
            if ($num_rows == 0) {
                $sql = 'SELECT attach_id, physical_filename, thumbnail
					FROM ' . ATTACHMENTS_DESC_TABLE . '
					WHERE attach_id = ' . (int) $attach_id_array[$i];
                if (!($result = $db->sql_query($sql))) {
                    message_die(GENERAL_ERROR, 'Couldn\'t query attach description table', '', __LINE__, __FILE__, $sql);
                }
                $num_rows = $db->sql_numrows($result);
                if ($num_rows != 0) {
                    $num_attach = $num_rows;
                    $attachments = $db->sql_fetchrowset($result);
                    $db->sql_freeresult($result);
                    // delete attachments
                    for ($j = 0; $j < $num_attach; $j++) {
                        unlink_attach($attachments[$j]['physical_filename']);
                        if (intval($attachments[$j]['thumbnail']) == 1) {
                            unlink_attach($attachments[$j]['physical_filename'], MODE_THUMBNAIL);
                        }
                        $sql = 'DELETE FROM ' . ATTACHMENTS_DESC_TABLE . '
							WHERE attach_id = ' . (int) $attachments[$j]['attach_id'];
                        if (!$db->sql_query($sql)) {
                            message_die(GENERAL_ERROR, $lang['Error_deleted_attachments'], '', __LINE__, __FILE__, $sql);
                        }
                    }
                } else {
                    $db->sql_freeresult($result);
                }
            }
        }
    }
    // Now Sync the Topic/PM
    if ($page == PAGE_PRIVMSGS) {
        for ($i = 0; $i < sizeof($post_id_array); $i++) {
            $sql = 'SELECT attach_id 
				FROM ' . ATTACHMENTS_TABLE . ' 
				WHERE privmsgs_id = ' . (int) $post_id_array[$i];
            if (!($result = $db->sql_query($sql))) {
                message_die(GENERAL_ERROR, 'Couldn\'t query Attachments Table', '', __LINE__, __FILE__, $sql);
            }
            $num_rows = $db->sql_numrows($result);
            $db->sql_freeresult($result);
            if ($num_rows == 0) {
                $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' SET privmsgs_attachment = 0 
					WHERE privmsgs_id = ' . $post_id_array[$i];
                if (!($result = $db->sql_query($sql))) {
                    message_die(GENERAL_ERROR, 'Couldn\'t update Private Message Attachment Switch', '', __LINE__, __FILE__, $sql);
                }
            }
        }
    } else {
        if (sizeof($post_id_array)) {
            $sql = 'SELECT topic_id 
				FROM ' . POSTS_TABLE . ' 
				WHERE post_id IN (' . implode(', ', $post_id_array) . ') 
				GROUP BY topic_id';
            if (!($result = $db->sql_query($sql))) {
                message_die(GENERAL_ERROR, 'Couldn\'t select Topic ID', '', __LINE__, __FILE__, $sql);
            }
            while ($row = $db->sql_fetchrow($result)) {
                attachment_sync_topic($row['topic_id']);
            }
            $db->sql_freeresult($result);
        }
    }
}
Exemplo n.º 4
0
/**
* Delete Attachment(s) from post(s) (intern)
*/
function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, $user_id = 0)
{
    global $bb_cfg;
    // Generate Array, if it's not an array
    if ($post_id_array === 0 && $attach_id_array === 0 && $page === 0) {
        return;
    }
    if ($post_id_array === 0 && $attach_id_array !== 0) {
        $post_id_array = array();
        if (!is_array($attach_id_array)) {
            if (strstr($attach_id_array, ', ')) {
                $attach_id_array = explode(', ', $attach_id_array);
            } else {
                if (strstr($attach_id_array, ',')) {
                    $attach_id_array = explode(',', $attach_id_array);
                } else {
                    $attach_id = intval($attach_id_array);
                    $attach_id_array = array();
                    $attach_id_array[] = $attach_id;
                }
            }
        }
        // Get the post_ids to fill the array
        $p_id = 'post_id';
        $sql = "SELECT {$p_id}\n\t\t\tFROM " . BB_ATTACHMENTS . '
				WHERE attach_id IN (' . implode(', ', $attach_id_array) . ")\n\t\t\tGROUP BY {$p_id}";
        if (!($result = DB()->sql_query($sql))) {
            bb_die('Could not select ids');
        }
        $num_post_list = DB()->num_rows($result);
        if ($num_post_list == 0) {
            DB()->sql_freeresult($result);
            return;
        }
        while ($row = DB()->sql_fetchrow($result)) {
            $post_id_array[] = intval($row[$p_id]);
        }
        DB()->sql_freeresult($result);
    }
    if (!is_array($post_id_array)) {
        if (trim($post_id_array) == '') {
            return;
        }
        if (strstr($post_id_array, ', ')) {
            $post_id_array = explode(', ', $post_id_array);
        } else {
            if (strstr($post_id_array, ',')) {
                $post_id_array = explode(',', $post_id_array);
            } else {
                $post_id = intval($post_id_array);
                $post_id_array = array();
                $post_id_array[] = $post_id;
            }
        }
    }
    if (!sizeof($post_id_array)) {
        return;
    }
    // First of all, determine the post id and attach_id
    if ($attach_id_array === 0) {
        $attach_id_array = array();
        // Get the attach_ids to fill the array
        $whereclause = 'WHERE post_id IN (' . implode(', ', $post_id_array) . ')';
        $sql = 'SELECT attach_id
			FROM ' . BB_ATTACHMENTS . " {$whereclause}\n\t\t\tGROUP BY attach_id";
        if (!($result = DB()->sql_query($sql))) {
            bb_die('Could not select attachment id #1');
        }
        $num_attach_list = DB()->num_rows($result);
        if ($num_attach_list == 0) {
            DB()->sql_freeresult($result);
            return;
        }
        while ($row = DB()->sql_fetchrow($result)) {
            $attach_id_array[] = (int) $row['attach_id'];
        }
        DB()->sql_freeresult($result);
    }
    if (!is_array($attach_id_array)) {
        if (strstr($attach_id_array, ', ')) {
            $attach_id_array = explode(', ', $attach_id_array);
        } else {
            if (strstr($attach_id_array, ',')) {
                $attach_id_array = explode(',', $attach_id_array);
            } else {
                $attach_id = intval($attach_id_array);
                $attach_id_array = array();
                $attach_id_array[] = $attach_id;
            }
        }
    }
    if (!sizeof($attach_id_array)) {
        return;
    }
    $sql_id = 'post_id';
    if (sizeof($post_id_array) && sizeof($attach_id_array)) {
        $sql = 'DELETE FROM ' . BB_ATTACHMENTS . '
			WHERE attach_id IN (' . implode(', ', $attach_id_array) . ")\n\t\t\t\tAND {$sql_id} IN (" . implode(', ', $post_id_array) . ')';
        if (!DB()->sql_query($sql)) {
            bb_die($lang['ERROR_DELETED_ATTACHMENTS']);
        }
        //bt
        if ($sql_id == 'post_id') {
            $sql = "SELECT topic_id FROM " . BB_BT_TORRENTS . " WHERE attach_id IN(" . implode(',', $attach_id_array) . ")";
            if (!($result = DB()->sql_query($sql))) {
                bb_die($lang['ERROR_DELETED_ATTACHMENTS']);
            }
            $torrents_sql = array();
            while ($row = DB()->sql_fetchrow($result)) {
                $torrents_sql[] = $row['topic_id'];
            }
            if ($torrents_sql = implode(',', $torrents_sql)) {
                // Remove peers from tracker
                $sql = "DELETE FROM " . BB_BT_TRACKER . "\n\t\t\t\t\tWHERE topic_id IN({$torrents_sql})";
                if (!DB()->sql_query($sql)) {
                    bb_die('Could not delete peers');
                }
            }
            // Delete torrents
            $sql = "DELETE FROM " . BB_BT_TORRENTS . "\n\t\t\t\tWHERE attach_id IN(" . implode(',', $attach_id_array) . ")";
            if (!DB()->sql_query($sql)) {
                bb_die($lang['ERROR_DELETED_ATTACHMENTS']);
            }
        }
        //bt end
        for ($i = 0; $i < sizeof($attach_id_array); $i++) {
            $sql = 'SELECT attach_id
				FROM ' . BB_ATTACHMENTS . '
						WHERE attach_id = ' . (int) $attach_id_array[$i];
            if (!($result = DB()->sql_query($sql))) {
                bb_die('Could not select Attachment id #2');
            }
            $num_rows = DB()->num_rows($result);
            DB()->sql_freeresult($result);
            if ($num_rows == 0) {
                $sql = 'SELECT attach_id, physical_filename, thumbnail
						FROM ' . BB_ATTACHMENTS_DESC . '
							WHERE attach_id = ' . (int) $attach_id_array[$i];
                if (!($result = DB()->sql_query($sql))) {
                    bb_die('Could not query attach description table');
                }
                $num_rows = DB()->num_rows($result);
                if ($num_rows != 0) {
                    $num_attach = $num_rows;
                    $attachments = DB()->sql_fetchrowset($result);
                    DB()->sql_freeresult($result);
                    // delete attachments
                    for ($j = 0; $j < $num_attach; $j++) {
                        unlink_attach($attachments[$j]['physical_filename']);
                        if (intval($attachments[$j]['thumbnail']) == 1) {
                            unlink_attach($attachments[$j]['physical_filename'], MODE_THUMBNAIL);
                        }
                        $sql = 'DELETE FROM ' . BB_ATTACHMENTS_DESC . ' WHERE attach_id = ' . (int) $attachments[$j]['attach_id'];
                        if (!DB()->sql_query($sql)) {
                            bb_die($lang['ERROR_DELETED_ATTACHMENTS']);
                        }
                    }
                } else {
                    DB()->sql_freeresult($result);
                }
            }
        }
    }
    // Now Sync the Topic/PM
    if (sizeof($post_id_array)) {
        $sql = 'SELECT topic_id
			FROM ' . BB_POSTS . '
			WHERE post_id IN (' . implode(', ', $post_id_array) . ')
			GROUP BY topic_id';
        if (!($result = DB()->sql_query($sql))) {
            bb_die('Could not select topic id');
        }
        while ($row = DB()->sql_fetchrow($result)) {
            attachment_sync_topic($row['topic_id']);
        }
        DB()->sql_freeresult($result);
    }
}
Exemplo n.º 5
0
function sync($type, $id = false)
{
    global $db;
    switch ($type) {
        case 'all forums':
            $result = $db->sql_query("SELECT forum_id FROM " . FORUMS_TABLE);
            while ($row = $db->sql_fetchrow($result)) {
                sync('forum', $row['forum_id']);
            }
            break;
        case 'all topics':
            $result = $db->sql_query("SELECT topic_id FROM " . TOPICS_TABLE);
            while ($row = $db->sql_fetchrow($result)) {
                sync('topic', $row['topic_id']);
            }
            break;
        case 'forum':
            $sql = "SELECT MAX(post_id) AS last_post, COUNT(post_id) AS total\n\t\t\t\tFROM " . POSTS_TABLE . " WHERE forum_id = {$id}";
            $result = $db->sql_query($sql);
            if ($row = $db->sql_fetchrow($result)) {
                $last_post = $row['last_post'] ? $row['last_post'] : 0;
                $total_posts = $row['total'] ? $row['total'] : 0;
            } else {
                $last_post = 0;
                $total_posts = 0;
            }
            $result = $db->sql_query("SELECT COUNT(topic_id) AS total FROM " . TOPICS_TABLE . " WHERE forum_id = {$id}");
            $total_topics = ($row = $db->sql_fetchrow($result)) ? $row['total'] ? $row['total'] : 0 : 0;
            $sql = "UPDATE " . FORUMS_TABLE . "\n\t\t\t\tSET forum_last_post_id = {$last_post}, forum_posts = {$total_posts}, forum_topics = {$total_topics}\n\t\t\t\tWHERE forum_id = {$id}";
            $db->sql_query($sql);
            break;
        case 'topic':
            $sql = "SELECT MAX(post_id) AS last_post, MIN(post_id) AS first_post, COUNT(post_id) AS total_posts\n\t\t\t\tFROM " . POSTS_TABLE . " WHERE topic_id = {$id}";
            $result = $db->sql_query($sql);
            if ($row = $db->sql_fetchrow($result)) {
                $sql = $row['total_posts'] ? "UPDATE " . TOPICS_TABLE . " SET topic_replies = " . ($row['total_posts'] - 1) . ", topic_first_post_id = " . $row['first_post'] . ", topic_last_post_id = " . $row['last_post'] : "DELETE FROM " . TOPICS_TABLE;
                $db->sql_query($sql . " WHERE topic_id = {$id}");
            }
            //			  if (defined('BBAttach_mod')) {
            attachment_sync_topic($id);
            break;
    }
    return true;
}
Exemplo n.º 6
0
    function sync($type, $id = false)
    {
        global $db, $cache, $config;
        switch ($type) {
            case 'all_forums':
                $sql = "SELECT forum_id\n\t\t\t\t\tFROM " . FORUMS_TABLE;
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $this->sync('forum', $row['forum_id']);
                }
                $db->sql_freeresult($result);
                $sql = "UPDATE " . FORUMS_TABLE . " f, " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p, " . USERS_TABLE . " u\n\t\t\t\t\tSET f.forum_last_topic_id = p.topic_id, f.forum_last_poster_id = p.poster_id, f.forum_last_post_subject = t.topic_title, f.forum_last_post_time = p.post_time, f.forum_last_poster_name = u.username, f.forum_last_poster_color = u.user_color\n\t\t\t\t\tWHERE f.forum_last_post_id = p.post_id\n\t\t\t\t\t\tAND t.topic_id = p.topic_id\n\t\t\t\t\t\tAND p.poster_id = u.user_id";
                $result = $db->sql_query($sql);
                break;
            case 'all_topics':
                $sql = "SELECT topic_id\n\t\t\t\t\tFROM " . TOPICS_TABLE;
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $this->sync('topic', $row['topic_id']);
                }
                $db->sql_freeresult($result);
                $sql = "UPDATE " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u, " . USERS_TABLE . " u2\n\t\t\t\t\tSET t.topic_first_post_id = p.post_id, t.topic_first_post_time = p.post_time, t.topic_first_poster_id = p.poster_id, t.topic_first_poster_name = u.username, t.topic_first_poster_color = u.user_color, t.topic_last_post_id = p2.post_id, t.topic_last_post_time = p2.post_time, t.topic_last_poster_id = p2.poster_id, t.topic_last_poster_name = u2.username, t.topic_last_poster_color = u2.user_color\n\t\t\t\t\tWHERE t.topic_first_post_id = p.post_id\n\t\t\t\t\t\tAND p.poster_id = u.user_id\n\t\t\t\t\t\tAND t.topic_last_post_id = p2.post_id\n\t\t\t\t\t\tAND p2.poster_id = u2.user_id";
                $db->sql_query($sql);
                break;
            case 'forum':
                $sql = "SELECT MAX(post_id) AS last_post, COUNT(post_id) AS total\n\t\t\t\t\tFROM " . POSTS_TABLE . "\n\t\t\t\t\tWHERE forum_id = " . (int) $id;
                $result = $db->sql_query($sql);
                if ($row = $db->sql_fetchrow($result)) {
                    $last_post = $row['last_post'] ? $row['last_post'] : 0;
                    $total_posts = $row['total'] ? $row['total'] : 0;
                } else {
                    $last_post = 0;
                    $total_posts = 0;
                }
                $sql = "SELECT COUNT(topic_id) AS total\n\t\t\t\t\tFROM " . TOPICS_TABLE . "\n\t\t\t\t\tWHERE forum_id = " . (int) $id;
                $result = $db->sql_query($sql);
                $total_topics = ($row = $db->sql_fetchrow($result)) ? $row['total'] ? $row['total'] : 0 : 0;
                $sql = "UPDATE " . FORUMS_TABLE . "\n\t\t\t\t\tSET forum_last_post_id = {$last_post}, forum_posts = {$total_posts}, forum_topics = {$total_topics}\n\t\t\t\t\tWHERE forum_id = " . (int) $id;
                $db->sql_query($sql);
                break;
            case 'topic':
                $sql = "SELECT MAX(post_id) AS last_post, MIN(post_id) AS first_post, COUNT(post_id) AS total_posts\n\t\t\t\t\tFROM " . POSTS_TABLE . "\n\t\t\t\t\tWHERE topic_id = " . (int) $id;
                $result = $db->sql_query($sql);
                if ($row = $db->sql_fetchrow($result)) {
                    if ($row['total_posts']) {
                        // Correct the details of this topic
                        $sql = 'UPDATE ' . TOPICS_TABLE . '
							SET topic_replies = ' . ($row['total_posts'] - 1) . ', topic_first_post_id = ' . $row['first_post'] . ', topic_last_post_id = ' . $row['last_post'] . "\n\t\t\t\t\t\t\tWHERE topic_id = {$id}";
                        $db->sql_query($sql);
                    } else {
                        // There are no replies to this topic
                        // Check if it is a move stub
                        $sql_move = 'SELECT topic_moved_id
							FROM ' . TOPICS_TABLE . "\n\t\t\t\t\t\t\tWHERE topic_id = " . (int) $id;
                        $result_move = $db->sql_query($sql_move);
                        if ($row = $db->sql_fetchrow($result_move)) {
                            if (!$row['topic_moved_id']) {
                                $sql = 'DELETE FROM ' . TOPICS_TABLE . " WHERE topic_id = " . (int) $id;
                                $db->sql_query($sql);
                            }
                        }
                        $db->sql_freeresult($result_move);
                    }
                }
                $db->sql_freeresult($result);
                if (!function_exists('attachment_sync_topic')) {
                    include IP_ROOT_PATH . ATTACH_MOD_PATH . 'includes/functions_delete.' . PHP_EXT;
                }
                attachment_sync_topic($id);
                break;
        }
        board_stats();
        return true;
    }
Exemplo n.º 7
0
function sync($type, $id = false)
{
    switch ($type) {
        case 'all forums':
            $sql = "SELECT forum_id\n\t\t\t\tFROM " . FORUMS_TABLE;
            if (!($result = DB()->sql_query($sql))) {
                message_die(GENERAL_ERROR, 'Could not get forum IDs', '', __LINE__, __FILE__, $sql);
            }
            while ($row = DB()->sql_fetchrow($result)) {
                sync('forum', $row['forum_id']);
            }
            break;
        case 'all topics':
            $sql = "SELECT topic_id\n\t\t\t\tFROM " . TOPICS_TABLE;
            if (!($result = DB()->sql_query($sql))) {
                message_die(GENERAL_ERROR, 'Could not get topic ID', '', __LINE__, __FILE__, $sql);
            }
            while ($row = DB()->sql_fetchrow($result)) {
                sync('topic', $row['topic_id']);
            }
            break;
        case 'forum':
            $sql = "SELECT MAX(post_id) AS last_post, COUNT(post_id) AS total\n\t\t\t\tFROM " . POSTS_TABLE . "\n\t\t\t\tWHERE forum_id = {$id}";
            if (!($result = DB()->sql_query($sql))) {
                message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql);
            }
            if ($row = DB()->sql_fetchrow($result)) {
                $last_post = $row['last_post'] ? $row['last_post'] : 0;
                $total_posts = $row['total'] ? $row['total'] : 0;
            } else {
                $last_post = 0;
                $total_posts = 0;
            }
            $sql = "SELECT COUNT(topic_id) AS total\n\t\t\t\tFROM " . TOPICS_TABLE . "\n\t\t\t\tWHERE forum_id = {$id}";
            if (!($result = DB()->sql_query($sql))) {
                message_die(GENERAL_ERROR, 'Could not get topic count', '', __LINE__, __FILE__, $sql);
            }
            $total_topics = ($row = DB()->sql_fetchrow($result)) ? $row['total'] ? $row['total'] : 0 : 0;
            $sql = "UPDATE " . FORUMS_TABLE . "\n\t\t\t\tSET forum_last_post_id = {$last_post}, forum_posts = {$total_posts}, forum_topics = {$total_topics}\n\t\t\t\tWHERE forum_id = {$id}";
            if (!DB()->sql_query($sql)) {
                message_die(GENERAL_ERROR, 'Could not update forum', '', __LINE__, __FILE__, $sql);
            }
            break;
        case 'topic':
            $sql = "SELECT MAX(post_id) AS last_post, MIN(post_id) AS first_post, COUNT(post_id) AS total_posts\n\t\t\t\tFROM " . POSTS_TABLE . "\n\t\t\t\tWHERE topic_id = {$id}";
            if (!($result = DB()->sql_query($sql))) {
                message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql);
            }
            if ($row = DB()->sql_fetchrow($result)) {
                $sql = $row['total_posts'] ? "UPDATE " . TOPICS_TABLE . " SET topic_replies = " . ($row['total_posts'] - 1) . ", topic_first_post_id = " . $row['first_post'] . ", topic_last_post_id = " . $row['last_post'] . " WHERE topic_id = {$id}" : "DELETE FROM " . TOPICS_TABLE . " WHERE topic_id = {$id}";
                if (!DB()->sql_query($sql)) {
                    message_die(GENERAL_ERROR, 'Could not update topic', '', __LINE__, __FILE__, $sql);
                }
            }
            attachment_sync_topic($id);
            break;
    }
    return true;
}
Exemplo n.º 8
0
function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, $user_id = 0)
{
    global $db;
    //
    // Generate Array, if it's not an array
    //
    if ($post_id_array < 1 && $attach_id_array < 1 && $page < 1) {
        return;
    }
    if ($post_id_array < 1 && $attach_id_array > 0) {
        $post_id_array = array();
        if (!is_array($attach_id_array)) {
            if (strstr($attach_id_array, ', ')) {
                $attach_id_array = explode(', ', $attach_id_array);
            } else {
                if (strstr($attach_id_array, ',')) {
                    $attach_id_array = explode(',', $attach_id_array);
                } else {
                    $attach_id = intval($attach_id_array);
                    $attach_id_array = array();
                    $attach_id_array[] = $attach_id;
                }
            }
        }
        // Get the post_ids to fill the array
        if ($page == PAGE_PRIVMSGS) {
            $p_id = 'privmsgs_id';
        } else {
            $p_id = 'post_id';
        }
        $result = $db->sql_query("SELECT " . $p_id . " FROM " . ATTACHMENTS_TABLE . " WHERE attach_id IN (" . implode(', ', $attach_id_array) . ") GROUP BY " . $p_id);
        $post_list = $db->sql_fetchrowset($result);
        $num_post_list = $db->sql_numrows($result);
        if ($num_post_list == 0) {
            return;
        }
        for ($i = 0; $i < $num_post_list; $i++) {
            $post_id_array[] = intval($post_list[$i][$p_id]);
        }
    }
    if (!is_array($post_id_array)) {
        if (trim($post_id_array) == '') {
            return;
        }
        if (strstr($post_id_array, ', ')) {
            $post_id_array = explode(', ', $post_id_array);
        } else {
            if (strstr($post_id_array, ',')) {
                $post_id_array = explode(',', $post_id_array);
            } else {
                $post_id = intval($post_id_array);
                $post_id_array = array();
                $post_id_array[] = $post_id;
            }
        }
    }
    if (count($post_id_array) == 0) {
        return;
    }
    //
    // First of all, determine the post id and attach_id
    //
    if ($attach_id_array < 1) {
        $attach_id_array = array();
        // Get the attach_ids to fill the array
        if ($page == PAGE_PRIVMSGS) {
            $whereclause = "WHERE privmsgs_id IN (" . implode(', ', $post_id_array) . ")";
        } else {
            $whereclause = "WHERE post_id IN (" . implode(', ', $post_id_array) . ")";
        }
        $result = $db->sql_query("SELECT attach_id FROM " . ATTACHMENTS_TABLE . " " . $whereclause . " GROUP BY attach_id");
        $attach_list = $db->sql_fetchrowset($result);
        $num_attach_list = $db->sql_numrows($result);
        if ($num_attach_list == 0) {
            return;
        }
        for ($i = 0; $i < $num_attach_list; $i++) {
            $attach_id_array[] = intval($attach_list[$i]['attach_id']);
        }
    }
    if (!is_array($attach_id_array)) {
        if (strstr($attach_id_array, ', ')) {
            $attach_id_array = explode(', ', $attach_id_array);
        } else {
            if (strstr($attach_id_array, ',')) {
                $attach_id_array = explode(',', $attach_id_array);
            } else {
                $attach_id = intval($attach_id_array);
                $attach_id_array = array();
                $attach_id_array[] = $attach_id;
            }
        }
    }
    if (count($attach_id_array) == 0) {
        return;
    }
    if ($page == PAGE_PRIVMSGS) {
        $sql_id = 'privmsgs_id';
        if ($user_id > 0) {
            $post_id_array_2 = array();
            for ($i = 0; $i < count($post_id_array); $i++) {
                $result = $db->sql_query("SELECT privmsgs_type, privmsgs_to_userid, privmsgs_from_userid\n\t\t\t\tFROM " . PRIVMSGS_TABLE . "\n\t\t\t\tWHERE privmsgs_id = " . $post_id_array[$i]);
                if ($db->sql_numrows($result) != 0) {
                    $row = $db->sql_fetchrow($result);
                    $privmsgs_type = $row['privmsgs_type'];
                    if ($privmsgs_type == PRIVMSGS_READ_MAIL || $privmsgs_type == PRIVMSGS_NEW_MAIL || $privmsgs_type == PRIVMSGS_UNREAD_MAIL) {
                        if ($row['privmsgs_to_userid'] == $user_id) {
                            $post_id_array_2[] = $post_id_array[$i];
                        }
                    } else {
                        if ($privmsgs_type == PRIVMSGS_SENT_MAIL) {
                            if ($row['privmsgs_from_userid'] == $user_id) {
                                $post_id_array_2[] = $post_id_array[$i];
                            }
                        } else {
                            if ($privmsgs_type == PRIVMSGS_SAVED_OUT_MAIL) {
                                if ($row['privmsgs_from_userid'] == $user_id) {
                                    $post_id_array_2[] = $post_id_array[$i];
                                }
                            } else {
                                if ($privmsgs_type == PRIVMSGS_SAVED_IN_MAIL) {
                                    if ($row['privmsgs_to_userid'] == $user_id) {
                                        $post_id_array_2[] = $post_id_array[$i];
                                    }
                                }
                            }
                        }
                    }
                }
            }
            $post_id_array = $post_id_array_2;
        }
    } else {
        $sql_id = 'post_id';
    }
    $db->sql_query("DELETE FROM " . ATTACHMENTS_TABLE . " WHERE attach_id IN (" . implode(', ', $attach_id_array) . ") AND " . $sql_id . " IN (" . implode(', ', $post_id_array) . ")");
    for ($i = 0; $i < count($attach_id_array); $i++) {
        $result = $db->sql_query("SELECT attach_id FROM " . ATTACHMENTS_TABLE . " WHERE attach_id = " . $attach_id_array[$i]);
        if ($db->sql_numrows($result) == 0) {
            $result = $db->sql_query('SELECT attach_id, physical_filename, thumbnail
			FROM ' . ATTACHMENTS_DESC_TABLE . '
			WHERE attach_id = ' . $attach_id_array[$i]);
            if ($db->sql_numrows($result) != 0) {
                $attachments = $db->sql_fetchrowset($result);
                $num_attach = $db->sql_numrows($result);
                //
                // delete attachments
                //
                for ($j = 0; $j < $num_attach; $j++) {
                    unlink_attach($attachments[$j]['physical_filename']);
                    if (intval($attachments[$j]['thumbnail']) == 1) {
                        unlink_attach($attachments[$j]['physical_filename'], MODE_THUMBNAIL);
                    }
                    $db->sql_query('DELETE FROM ' . ATTACHMENTS_DESC_TABLE . '
					WHERE attach_id = ' . $attachments[$j]['attach_id']);
                }
            }
        }
    }
    //
    // Now Sync the Topic/PM
    //
    if ($page == PAGE_PRIVMSGS) {
        for ($i = 0; $i < count($post_id_array); $i++) {
            $result = $db->sql_query("SELECT attach_id FROM " . ATTACHMENTS_TABLE . " WHERE privmsgs_id = " . $post_id_array[$i]);
            if ($db->sql_numrows($result) == 0) {
                $result = $db->sql_query("UPDATE " . PRIVMSGS_TABLE . " SET privmsgs_attachment = 0 WHERE privmsgs_id = " . $post_id_array[$i]);
            }
        }
    } else {
        $result = $db->sql_query("SELECT topic_id FROM " . POSTS_TABLE . " WHERE post_id IN (" . implode(', ', $post_id_array) . ") GROUP BY topic_id");
        $row = $db->sql_fetchrowset($result);
        $num_rows = $db->sql_numrows($result);
        for ($i = 0; $i < $num_rows; $i++) {
            attachment_sync_topic($row[$i]['topic_id']);
        }
    }
}