function thread_split($tid, $spid, $split_type, &$error_str)
{
    if (!($db = db::get())) {
        return false;
    }
    if (!is_numeric($tid)) {
        return false;
    }
    if (!is_numeric($spid)) {
        return false;
    }
    if (!in_array($split_type, array(THREAD_SPLIT_REPLIES, THREAD_SPLIT_FOLLOWING))) {
        return false;
    }
    if (!($table_prefix = get_table_prefix())) {
        return thread_split_error(THREAD_SPLIT_FORUM_ERROR, $error_str);
    }
    if (!($thread_data = thread_get($tid))) {
        return thread_split_error(THREAD_SPLIT_THREAD_ERROR, $error_str);
    }
    if (!($forum_fid = get_forum_fid())) {
        return thread_split_error(THREAD_SPLIT_THREAD_ERROR, $error_str);
    }
    if (!is_numeric($spid) || $spid < 2 || $spid > $thread_data['LENGTH']) {
        return thread_split_error(THREAD_SPLIT_INVALID_ARGS, $error_str);
    }
    if (!is_numeric($split_type)) {
        return thread_split_error(THREAD_SPLIT_INVALID_ARGS, $error_str);
    }
    thread_set_closed($tid, true);
    $pid_array = array();
    switch ($split_type) {
        case THREAD_SPLIT_REPLIES:
            $pid_array = thread_split_get_replies($tid, $spid, $pid_array);
            break;
        case THREAD_SPLIT_FOLLOWING:
            $pid_array = thread_split_get_following($tid, $spid, $pid_array);
            break;
    }
    if (!is_array($pid_array) || sizeof($pid_array) < 1) {
        thread_split_error(THREAD_SPLIT_POST_ERROR, $error_str);
        thread_set_closed($tid, $thread_data['CLOSED'] > 0);
        return false;
    }
    if (!($new_tid = post_create_thread($thread_data['FID'], $thread_data['BY_UID'], $thread_data['TITLE'], 'N', 'N', true))) {
        thread_split_error(THREAD_SPLIT_CREATE_ERROR, $error_str);
        thread_set_closed($tid, $thread_data['CLOSED'] > 0);
        return false;
    }
    if (!($thread_new = thread_get($new_tid, true, true))) {
        thread_split_error(THREAD_SPLIT_CREATE_ERROR, $error_str);
        thread_set_closed($tid, $thread_data['CLOSED'] > 0);
        return false;
    }
    $pid_list = implode(',', $pid_array);
    $sql = "INSERT INTO `{$table_prefix}POST` (TID, REPLY_TO_PID, ";
    $sql .= "FROM_UID, TO_UID, VIEWED, CREATED, STATUS, APPROVED, APPROVED_BY, ";
    $sql .= "EDITED, EDITED_BY, IPADDRESS, MOVED_TID, MOVED_PID) ";
    $sql .= "SELECT '{$new_tid}', REPLY_TO_PID, FROM_UID, TO_UID, NULL, NOW(), ";
    $sql .= "STATUS, APPROVED, APPROVED_BY, EDITED, EDITED_BY, IPADDRESS, TID, ";
    $sql .= "PID FROM `{$table_prefix}POST` WHERE TID = {$tid} ";
    $sql .= "AND PID IN ({$pid_list}) ORDER BY CREATED";
    if (!$db->query($sql)) {
        // Unlock the original thread if it wasn't originally locked.
        thread_set_closed($tid, $thread_data['CLOSED'] > 0);
        // Return error message.
        return thread_split_error(THREAD_SPLIT_QUERY_ERROR, $error_str);
    }
    // Copy the post contents to the new thread
    $sql = "INSERT INTO `{$table_prefix}POST_CONTENT` (TID, PID, CONTENT) ";
    $sql .= "SELECT POST.TID, POST.PID, POST_CONTENT.CONTENT FROM `{$table_prefix}POST` POST ";
    $sql .= "LEFT JOIN `{$table_prefix}POST_CONTENT` POST_CONTENT ";
    $sql .= "ON (POST_CONTENT.TID = POST.MOVED_TID AND POST_CONTENT.PID = MOVED_PID) ";
    $sql .= "WHERE POST.TID = '{$new_tid}'";
    if (!$db->query($sql)) {
        // Unlock the original thread if it wasn't originally locked.
        thread_set_closed($tid, $thread_data['CLOSED'] > 0);
        // Return error message.
        return thread_split_error(THREAD_SPLIT_QUERY_ERROR, $error_str);
    }
    // Insert the new Sphinx Search IDs.
    $sql = "INSERT INTO `{$table_prefix}POST_SEARCH_ID` (TID, PID) ";
    $sql .= "SELECT {$new_tid}, POST.PID FROM `{$table_prefix}POST` POST ";
    $sql .= "WHERE POST.TID = '{$new_tid}'";
    if (!$db->query($sql)) {
        // Unlock the original thread if it wasn't originally locked.
        thread_set_closed($tid, $thread_data['CLOSED'] > 0);
        // Return error message.
        return thread_merge_error(THREAD_MERGE_QUERY_ERROR, $error_str);
    }
    // Update the REPLY_TO_PIDs in the new thread
    $sql = "INSERT INTO `{$table_prefix}POST` (TID, PID, REPLY_TO_PID) ";
    $sql .= "SELECT TARGET_POST.TID, TARGET_POST.PID, SOURCE_POST.PID ";
    $sql .= "FROM `{$table_prefix}POST` TARGET_POST ";
    $sql .= "INNER JOIN `{$table_prefix}POST` SOURCE_POST ";
    $sql .= "ON (SOURCE_POST.MOVED_TID = TARGET_POST.MOVED_TID ";
    $sql .= "AND TARGET_POST.REPLY_TO_PID = SOURCE_POST.MOVED_PID) ";
    $sql .= "WHERE TARGET_POST.TID = '{$new_tid}' AND TARGET_POST.PID > 1 ";
    $sql .= "ON DUPLICATE KEY UPDATE REPLY_TO_PID = VALUES(REPLY_TO_PID) ";
    if (!$db->query($sql)) {
        // Unlock the original thread if it wasn't originally locked.
        thread_set_closed($tid, $thread_data['CLOSED'] > 0);
        // Return error message.
        return thread_merge_error(THREAD_SPLIT_QUERY_ERROR, $error_str);
    }
    // Remove the first post in the thread's REPLY_TO_PID
    $sql = "UPDATE `{$table_prefix}POST` POST SET REPLY_TO_PID = NULL ";
    $sql .= "WHERE POST.TID = '{$new_tid}' AND POST.PID = 1";
    if (!$db->query($sql)) {
        // Unlock the original thread if it wasn't originally locked.
        thread_set_closed($tid, $thread_data['CLOSED'] > 0);
        // Return error message.
        return thread_merge_error(THREAD_SPLIT_QUERY_ERROR, $error_str);
    }
    // Update the old thread's post MOVED_TID and MOVED_PID
    $sql = "INSERT INTO `{$table_prefix}POST` (TID, PID, MOVED_TID, MOVED_PID) ";
    $sql .= "SELECT {$tid}, MOVED_PID, {$new_tid}, PID FROM `{$table_prefix}POST` POST ";
    $sql .= "WHERE POST.TID = {$new_tid} ON DUPLICATE KEY UPDATE MOVED_TID = VALUES(MOVED_TID), ";
    $sql .= "MOVED_PID = VALUES(MOVED_PID)";
    if (!$db->query($sql)) {
        // Unlock the original thread if it wasn't originally locked.
        thread_set_closed($tid, $thread_data['CLOSED'] > 0);
        // Return error message.
        return thread_merge_error(THREAD_SPLIT_QUERY_ERROR, $error_str);
    }
    // Link the attachments to the new thread.
    $sql = "INSERT INTO POST_ATTACHMENT_IDS (FID, TID, PID, AID) ";
    $sql .= "SELECT {$forum_fid}, TARGET_POST.TID, TARGET_POST.PID, ";
    $sql .= "SOURCE_POST_ATTACHMENT_IDS.AID ";
    $sql .= "FROM `{$table_prefix}POST` TARGET_POST ";
    $sql .= "INNER JOIN `{$table_prefix}POST` SOURCE_POST ";
    $sql .= "ON (SOURCE_POST.MOVED_TID = TARGET_POST.MOVED_TID ";
    $sql .= "AND TARGET_POST.REPLY_TO_PID = SOURCE_POST.MOVED_PID) ";
    $sql .= "INNER JOIN POST_ATTACHMENT_IDS SOURCE_POST_ATTACHMENT_IDS ";
    $sql .= "ON (SOURCE_POST_ATTACHMENT_IDS.TID = SOURCE_POST.TID ";
    $sql .= "AND SOURCE_POST_ATTACHMENT_IDS.PID = SOURCE_POST.PID) ";
    $sql .= "WHERE TARGET_POST.TID = '{$new_tid}'";
    if (!$db->query($sql)) {
        // Unlock the original thread if it wasn't originally locked.
        thread_set_closed($tid, $thread_data['CLOSED'] > 0);
        // Return error message.
        return thread_merge_error(THREAD_SPLIT_QUERY_ERROR, $error_str);
    }
    // Now we unset the MOVED_TID and MOVED_PIDs for the new thread
    // so the posts appear in the new thread.
    $sql = "UPDATE `{$table_prefix}POST` SET MOVED_TID = NULL, ";
    $sql .= "MOVED_PID = NULL WHERE TID = '{$new_tid}'";
    if (!$db->query($sql)) {
        // Unlock the original thread if it wasn't originally locked.
        thread_set_closed($tid, $thread_data['CLOSED'] > 0);
        // Return error message.
        return thread_merge_error(THREAD_SPLIT_QUERY_ERROR, $error_str);
    }
    thread_set_split($tid, $new_tid);
    thread_set_length($new_tid, sizeof($pid_array));
    thread_set_closed($tid, $thread_data['CLOSED'] > 0);
    thread_set_closed($new_tid, $thread_data['CLOSED'] > 0);
    return array($tid, $spid, $new_tid, $thread_new['TITLE']);
}
Exemple #2
0
    if (perm_get_user_permissions($reply_message['FROM_UID']) & USER_PERM_WORMED && !session::check_perm(USER_PERM_FOLDER_MODERATE, $t_fid) || (!isset($reply_message['CONTENT']) || $reply_message['CONTENT'] == "") && $thread_data['POLL_FLAG'] != 'Y' && $reply_to_pid != 0) {
        html_draw_error(gettext("Message not found. Check that it hasn't been deleted."));
    }
}
if ($valid && isset($_POST['post'])) {
    if (post_check_frequency()) {
        if (post_check_ddkey($t_dedupe)) {
            if ($new_thread) {
                if (session::check_perm(USER_PERM_FOLDER_MODERATE, $t_fid)) {
                    $t_closed = isset($_POST['t_closed']) && $_POST['t_closed'] == 'Y' ? true : false;
                    $t_sticky = isset($_POST['t_sticky']) && $_POST['t_sticky'] == 'Y' ? 'Y' : 'N';
                } else {
                    $t_closed = false;
                    $t_sticky = "N";
                }
                $t_tid = post_create_thread($t_fid, $uid, $t_threadtitle, "N", $t_sticky, $t_closed);
                $t_rpid = 0;
            } else {
                $t_tid = isset($_POST['t_tid']) && is_numeric($_POST['t_tid']) ? $_POST['t_tid'] : 0;
                $t_rpid = isset($_POST['t_rpid']) && is_numeric($_POST['t_rpid']) ? $_POST['t_rpid'] : 0;
                if (isset($thread_data['CLOSED']) && $thread_data['CLOSED'] > 0 && !session::check_perm(USER_PERM_FOLDER_MODERATE, $t_fid)) {
                    html_draw_error(gettext("This thread is closed, you cannot post in it!"));
                }
                if (session::check_perm(USER_PERM_FOLDER_MODERATE, $t_fid)) {
                    $t_closed = isset($_POST['t_closed']) && $_POST['t_closed'] == 'Y' ? true : false;
                    $t_sticky = isset($_POST['t_sticky']) && $_POST['t_sticky'] == 'Y' ? 'Y' : 'N';
                    if (isset($t_closed) && $t_closed == "Y") {
                        thread_set_closed($t_tid, true);
                    } else {
                        thread_set_closed($t_tid, false);
                    }
             $poll_closes = time() + DAY_IN_SECONDS * 3;
         } else {
             if ($close_poll == POLL_CLOSE_SEVEN_DAYS) {
                 $poll_closes = time() + DAY_IN_SECONDS * 7;
             } else {
                 if ($close_poll == POLL_CLOSE_THIRTY_DAYS) {
                     $poll_closes = time() + DAY_IN_SECONDS * 30;
                 } else {
                     if ($close_poll == POLL_CLOSE_NEVER) {
                         $poll_closes = false;
                     }
                 }
             }
         }
     }
     $tid = post_create_thread($fid, $uid, $thread_title, 'Y', 'N');
     $pid = post_create($fid, $tid, 0, $uid, 0, '');
     poll_create($tid, $poll_questions_array, $poll_closes, $change_vote, $poll_type, $show_results, $poll_vote_type, $option_type, $allow_guests);
     post_save_attachment_id($tid, $pid, $aid);
     if (strlen($message_text) > 0) {
         if ($allow_sig == true && strlen(trim($sig_text)) > 0) {
             $message_text .= "<div class=\"sig\">{$sig_text}</div>";
         }
         post_create($fid, $tid, 1, $uid, $uid, $message_text);
     }
     if ($high_interest == "Y") {
         thread_set_high_interest($tid);
     }
 }
 if (isset($tid) && $tid > 0) {
     $uri = "discussion.php?webtag={$webtag}&msg={$tid}.1";
Exemple #4
0
if (isset($fid) && !session::check_perm(USER_PERM_SIGNATURE, $fid)) {
    $allow_sig = false;
}
if ($allow_html == false) {
    $content = htmlentities_array($content);
    $sig = htmlentities_array($sig);
}
if (mb_strlen($content) + mb_strlen($sig) >= 65535) {
    $error_msg_array[] = sprintf(gettext("Combined Message and signature length must be less than 65,535 characters (currently: %s)"), format_number(mb_strlen($content) + mb_strlen($sig)));
    $valid = false;
}
if ($valid && isset($_POST['post'])) {
    if (post_check_frequency()) {
        if (post_check_ddkey($dedupe)) {
            if ($new_thread) {
                $tid = post_create_thread($fid, $_SESSION['UID'], $threadtitle, 'N', 'N', false);
                $reply_to_pid = 0;
            } else {
                if (isset($thread_data['CLOSED']) && $thread_data['CLOSED'] > 0 && !session::check_perm(USER_PERM_FOLDER_MODERATE, $fid)) {
                    light_html_draw_error(gettext("This thread is closed, you cannot post in it!"));
                }
            }
            if (isset($tid) && is_numeric($tid)) {
                if ($allow_sig == true && strlen(trim($sig)) > 0) {
                    $content .= "<div class=\"sig\">{$sig}</div>";
                }
                if (($new_pid = post_create($fid, $tid, $reply_to_pid, $_SESSION['UID'], $to_logon_array, $content)) !== false) {
                    if ($high_interest == "Y") {
                        thread_set_high_interest($tid);
                    }
                    email_send_notification($tid, $new_pid);
         $poll_closes = time() + DAY_IN_SECONDS * 3;
     } else {
         if ($close_poll == POLL_CLOSE_SEVEN_DAYS) {
             $poll_closes = time() + DAY_IN_SECONDS * 7;
         } else {
             if ($close_poll == POLL_CLOSE_THIRTY_DAYS) {
                 $poll_closes = time() + DAY_IN_SECONDS * 30;
             } else {
                 if ($close_poll == POLL_CLOSE_NEVER) {
                     $poll_closes = false;
                 }
             }
         }
     }
 }
 if ($tid = post_create_thread($fid, $_SESSION['UID'], $thread_title, 'Y', 'N')) {
     if ($new_pid = post_create($fid, $tid, 0, $_SESSION['UID'], array(), '')) {
         poll_create($tid, $poll_questions_array, $poll_closes, $change_vote, $poll_type, $show_results, $poll_vote_type, $option_type, $allow_guests);
         email_send_notification($tid, $new_pid);
         email_send_thread_subscription($tid, $new_pid);
         email_send_folder_subscription($fid, $tid);
         if (perm_check_folder_permissions($fid, USER_PERM_POST_APPROVAL, $_SESSION['UID']) && !perm_is_moderator($_SESSION['UID'], $fid)) {
             admin_send_post_approval_notification($fid);
         }
         if (sizeof($attachments) > 0 && ($attachments_array = attachments_get($_SESSION['UID'], $attachments)) !== false) {
             foreach ($attachments_array as $attachment) {
                 post_add_attachment($tid, $new_pid, $attachment['aid']);
             }
         }
         if (strlen($message_text) > 0) {
             if ($allow_sig == true && strlen(trim($sig_text)) > 0) {
Exemple #6
0
if (mb_strlen($content) + mb_strlen($sig) >= 65535) {
    $error_msg_array[] = sprintf(gettext("Combined Message and signature length must be less than 65,535 characters (currently: %s)"), format_number(mb_strlen($content) + mb_strlen($sig)));
    $valid = false;
}
if ($valid && isset($_POST['post'])) {
    if (post_check_frequency()) {
        if (post_check_ddkey($dedupe)) {
            if ($new_thread) {
                if (session::check_perm(USER_PERM_FOLDER_MODERATE, $fid)) {
                    $closed = isset($_POST['closed']) && $_POST['closed'] == 'Y' ? true : false;
                    $sticky = isset($_POST['sticky']) && $_POST['sticky'] == 'Y' ? 'Y' : 'N';
                } else {
                    $closed = false;
                    $sticky = "N";
                }
                $tid = post_create_thread($fid, $_SESSION['UID'], $threadtitle, "N", $sticky, $closed);
                $reply_to_pid = 0;
            } else {
                if (isset($thread_data['CLOSED']) && $thread_data['CLOSED'] > 0 && !session::check_perm(USER_PERM_FOLDER_MODERATE, $fid)) {
                    html_draw_error(gettext("This thread is closed, you cannot post in it!"));
                }
                if (session::check_perm(USER_PERM_FOLDER_MODERATE, $fid)) {
                    $closed = isset($_POST['closed']) && $_POST['closed'] == 'Y' ? true : false;
                    $sticky = isset($_POST['sticky']) && $_POST['sticky'] == 'Y' ? 'Y' : 'N';
                    if (isset($closed) && $closed == "Y") {
                        thread_set_closed($tid, true);
                    } else {
                        thread_set_closed($tid, false);
                    }
                    if (isset($sticky) && $sticky == "Y") {
                        thread_set_sticky($tid, true);
Exemple #7
0
    if (!($reply_message = messages_get($reply_to_tid, $reply_to_pid))) {
        light_html_draw_error(gettext("That post does not exist in this thread!"));
    }
    if (!($thread_data = thread_get($reply_to_tid))) {
        light_html_draw_error(gettext("The requested thread could not be found or access was denied."));
    }
    $reply_message['CONTENT'] = message_get_content($reply_to_tid, $reply_to_pid);
    if (perm_get_user_permissions($reply_message['FROM_UID']) & USER_PERM_WORMED && !session::check_perm(USER_PERM_FOLDER_MODERATE, $t_fid) || (!isset($reply_message['CONTENT']) || $reply_message['CONTENT'] == "") && $thread_data['POLL_FLAG'] != 'Y' && $reply_to_pid != 0) {
        light_html_draw_error(gettext("Message not found. Check that it hasn't been deleted."));
    }
}
if ($valid && isset($_POST['post'])) {
    if (post_check_frequency()) {
        if (post_check_ddkey($t_dedupe)) {
            if ($new_thread) {
                $t_tid = post_create_thread($t_fid, $uid, $t_threadtitle, 'N', 'N', false);
                $t_rpid = 0;
            } else {
                $t_tid = isset($_POST['t_tid']) && is_numeric($_POST['t_tid']) ? $_POST['t_tid'] : 0;
                $t_rpid = isset($_POST['t_rpid']) && is_numeric($_POST['t_rpid']) ? $_POST['t_rpid'] : 0;
                if (isset($thread_data['CLOSED']) && $thread_data['CLOSED'] > 0 && !session::check_perm(USER_PERM_FOLDER_MODERATE, $t_fid)) {
                    light_html_draw_error(gettext("This thread is closed, you cannot post in it!"));
                }
            }
            if ($t_tid > 0) {
                if ($allow_sig == true && strlen(trim($t_sig)) > 0) {
                    $t_content .= "<div class=\"sig\">{$t_sig}</div>";
                }
                $new_pid = post_create($t_fid, $t_tid, $t_rpid, $uid, $t_to_uid, $t_content);
                if ($new_pid > -1) {
                    $user_rel = user_get_relationship($t_to_uid, $uid);
function rss_feed_check_feeds()
{
    if (($rss_feed = rss_feed_fetch()) !== false) {
        if (($rss_data = rss_feed_read_database($rss_feed['URL'])) !== false) {
            $max_item_count = min(10, $rss_feed['MAX_ITEM_COUNT']);
            foreach ($rss_data as $item_index => $rss_feed_item) {
                if ($item_index + 1 > $max_item_count) {
                    return;
                }
                if (!rss_feed_thread_exist($rss_feed['RSSID'], $rss_feed_item->link)) {
                    $rss_title = htmlentities_decode_array($rss_feed_item->title);
                    $rss_title = htmlentities_array(strip_tags($rss_title));
                    $rss_feed_name = htmlentities_array($rss_feed['NAME']);
                    $rss_quote_source = "{$rss_feed_name} {$rss_title}";
                    if (isset($rss_feed['PREFIX']) && strlen(trim($rss_feed['PREFIX'])) > 0) {
                        $rss_feed_prefix = htmlentities_array($rss_feed['PREFIX']);
                        $rss_title = "{$rss_feed_prefix} {$rss_title}";
                    }
                    if (mb_strlen($rss_title) > 64) {
                        $rss_title = mb_substr($rss_title, 0, 60);
                        if (($pos = mb_strrpos($rss_title, ' ')) !== false) {
                            $rss_title = trim(mb_substr($rss_title, 0, $pos));
                        }
                        $rss_title .= "...";
                    }
                    if (strlen($rss_feed_item->description) > 1) {
                        $rss_feed_item_description = htmlentities_decode_array($rss_feed_item->description);
                        $rss_content = fix_html(sprintf('<div class="quotetext"><b>%s:</b> <a href="%s">%s</a></div>
                             <div class="quote">%s</div>', gettext('quote'), $rss_feed_item->link, $rss_quote_source, $rss_feed_item_description));
                    } else {
                        $rss_content = fix_html(sprintf('<p>%s</p><a href=\\"%s\\" target=\\"_blank\\">%s</a>', $rss_quote_source, $rss_feed_item->link, gettext("Click here to read this article")));
                    }
                    $tid = post_create_thread($rss_feed['FID'], $rss_feed['UID'], $rss_title);
                    post_create($rss_feed['FID'], $tid, 0, $rss_feed['UID'], array(), $rss_content);
                    rss_feed_create_history($rss_feed['RSSID'], $rss_feed_item->link);
                }
            }
        }
    }
}