コード例 #1
0
ファイル: functions_newpost.php プロジェクト: holandacz/nb4
/**
 * Creates a new post
 *
 * @param	string	'thread' for the first post in a new thread, 'reply' otherwise
 * @param	array	Forum Information
 * @param	array	Thread Information
 * @param	array	Post Information for the "Parent" post
 * @param	array	Post Information for the post being created
 * @param	array	(return) Array of errors
 *
 */
function build_new_post($type = 'thread', $foruminfo, $threadinfo, $postinfo, &$post, &$errors)
{
    //NOTE: permissions are not checked in this function
    // $post is passed by reference, so that any changes (wordwrap, censor, etc) here are reflected on the copy outside the function
    // $post[] includes:
    // title, iconid, message, parseurl, email, signature, preview, disablesmilies, rating
    // $errors will become any error messages that come from the checks before preview kicks in
    global $vbulletin, $vbphrase, $forumperms;
    // ### PREPARE OPTIONS AND CHECK VALID INPUT ###
    $post['disablesmilies'] = intval($post['disablesmilies']);
    $post['enablesmilies'] = $post['disablesmilies'] ? 0 : 1;
    $post['folderid'] = intval($post['folderid']);
    $post['emailupdate'] = intval($post['emailupdate']);
    $post['rating'] = intval($post['rating']);
    $post['podcastsize'] = intval($post['podcastsize']);
    /*$post['parseurl'] = intval($post['parseurl']);
    	$post['email'] = intval($post['email']);
    	$post['signature'] = intval($post['signature']);
    	$post['preview'] = iif($post['preview'], 1, 0);
    	$post['iconid'] = intval($post['iconid']);
    	$post['message'] = trim($post['message']);
    	$post['title'] = trim(preg_replace('/&#0*32;/', ' ', $post['title']));
    	$post['username'] = trim($post['username']);
    	$post['posthash'] = trim($post['posthash']);
    	$post['poststarttime'] = trim($post['poststarttime']);*/
    // Make sure the posthash is valid
    if (md5($post['poststarttime'] . $vbulletin->userinfo['userid'] . $vbulletin->userinfo['salt']) != $post['posthash']) {
        $post['posthash'] = 'invalid posthash';
        // don't phrase me
    }
    // OTHER SANITY CHECKS
    $threadinfo['threadid'] = intval($threadinfo['threadid']);
    // create data manager
    if ($type == 'thread') {
        $dataman =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
        $dataman->set('prefixid', $post['prefixid']);
    } else {
        $dataman =& datamanager_init('Post', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
    }
    // set info
    $dataman->set_info('preview', $post['preview']);
    $dataman->set_info('parseurl', $post['parseurl']);
    $dataman->set_info('posthash', $post['posthash']);
    $dataman->set_info('forum', $foruminfo);
    $dataman->set_info('thread', $threadinfo);
    if (!$vbulletin->GPC['fromquickreply']) {
        $dataman->set_info('show_title_error', true);
    }
    if ($foruminfo['podcast'] and (!empty($post['podcasturl']) or !empty($post['podcastexplicit']) or !empty($post['podcastauthor']) or !empty($post['podcastsubtitle']) or !empty($post['podcastkeywords']))) {
        $dataman->set_info('podcastexplicit', $post['podcastexplicit']);
        $dataman->set_info('podcastauthor', $post['podcastauthor']);
        $dataman->set_info('podcastkeywords', $post['podcastkeywords']);
        $dataman->set_info('podcastsubtitle', $post['podcastsubtitle']);
        $dataman->set_info('podcasturl', $post['podcasturl']);
        if ($post['podcastsize']) {
            $dataman->set_info('podcastsize', $post['podcastsize']);
        }
    }
    // set options
    $dataman->setr('showsignature', $post['signature']);
    $dataman->setr('allowsmilie', $post['enablesmilies']);
    // set data
    $dataman->setr('userid', $vbulletin->userinfo['userid']);
    if ($vbulletin->userinfo['userid'] == 0) {
        $dataman->setr('username', $post['username']);
    }
    $dataman->setr('title', $post['title']);
    $dataman->setr('pagetext', $post['message']);
    $dataman->setr('iconid', $post['iconid']);
    // see if post has to be moderated or if poster in a mod
    if (($foruminfo['moderatenewthread'] and $type == 'thread' or $foruminfo['moderatenewpost'] and $type == 'reply' or !($forumperms & $vbulletin->bf_ugp_forumpermissions['followforummoderation'])) and !can_moderate($foruminfo['forumid']) or $type == 'reply' and ($postinfo['postid'] and !$postinfo['visible'] and !empty($postinfo['specifiedpost']) or !$threadinfo['visible'])) {
        // note: specified post comes from a variable passed into newreply.php
        $dataman->set('visible', 0);
        $post['visible'] = 0;
    } else {
        $dataman->set('visible', 1);
        $post['visible'] = 1;
    }
    if ($type != 'thread') {
        if ($postinfo['postid'] == 0) {
            // get parentid of the new post
            // we're not posting a new thread, so make this post a child of the first post in the thread
            $getfirstpost = $vbulletin->db->query_first("SELECT postid FROM " . TABLE_PREFIX . "post WHERE threadid={$threadinfo['threadid']} ORDER BY dateline LIMIT 1");
            $parentid = $getfirstpost['postid'];
        } else {
            $parentid = $postinfo['postid'];
        }
        $dataman->setr('parentid', $parentid);
        $dataman->setr('threadid', $threadinfo['threadid']);
    } else {
        $dataman->setr('forumid', $foruminfo['forumid']);
    }
    $errors = array();
    // done!
    ($hook = vBulletinHook::fetch_hook('newpost_process')) ? eval($hook) : false;
    if ($vbulletin->GPC['fromquickreply'] and $post['preview']) {
        $errors = array();
        return;
    }
    if ($vbulletin->options['hvcheck_post'] and !$post['preview'] and !$vbulletin->userinfo['userid']) {
        require_once DIR . '/includes/class_humanverify.php';
        $verify =& vB_HumanVerify::fetch_library($vbulletin);
        if (!$verify->verify_token($post['humanverify'])) {
            $dataman->error($verify->fetch_error());
        }
    }
    if ($dataman->info['podcastsize']) {
        $post['podcastsize'] = $dataman->info['podcastsize'];
    }
    // check if this forum requires a prefix
    if ($type == 'thread' and !$dataman->fetch_field('prefixid') and $foruminfo['options'] & $vbulletin->bf_misc_forumoptions['prefixrequired']) {
        // only require a prefix if we actually have options for this forum
        require_once DIR . '/includes/functions_prefix.php';
        if (fetch_prefix_array($foruminfo['forumid'])) {
            $dataman->error('thread_prefix_required');
        }
    }
    if ($type == 'thread' and $post['taglist']) {
        fetch_valid_tags($dataman->thread, $post['taglist'], $tag_errors, true, false);
        if ($tag_errors) {
            foreach ($tag_errors as $error) {
                $dataman->error($error);
            }
        }
    }
    $dataman->pre_save();
    $errors = array_merge($errors, $dataman->errors);
    if ($post['preview']) {
        return;
    }
    // ### DUPE CHECK ###
    $dupehash = md5($foruminfo['forumid'] . $post['title'] . $post['message'] . $vbulletin->userinfo['userid'] . $type);
    $prevpostfound = false;
    $prevpostthreadid = 0;
    if ($prevpost = $vbulletin->db->query_first("\n\t\tSELECT posthash.threadid\n\t\tFROM " . TABLE_PREFIX . "posthash AS posthash\n\t\tWHERE posthash.userid = " . $vbulletin->userinfo['userid'] . " AND\n\t\t\tposthash.dupehash = '" . $vbulletin->db->escape_string($dupehash) . "' AND\n\t\t\tposthash.dateline > " . (TIMENOW - 300) . "\n\t")) {
        if ($type == 'thread' and $prevpost['threadid'] == 0 or $type == 'reply' and $prevpost['threadid'] == $threadinfo['threadid']) {
            $prevpostfound = true;
            $prevpostthreadid = $prevpost['threadid'];
        }
    }
    // Redirect user to forumdisplay since this is a duplicate post
    if ($prevpostfound) {
        if ($type == 'thread') {
            $vbulletin->url = 'forumdisplay.php?' . $vbulletin->session->vars['sessionurl'] . "f={$foruminfo['forumid']}";
            eval(print_standard_redirect('redirect_duplicatethread', true, true));
        } else {
            // with ajax quick reply we need to use the error system
            if ($vbulletin->GPC['ajax']) {
                $dataman->error('duplicate_post');
                $errors = $dataman->errors;
                return;
            } else {
                $vbulletin->url = 'showthread.php?' . $vbulletin->session->vars['sessionurl'] . "t={$prevpostthreadid}&goto=newpost";
                if ($post['ajaxqrfailed']) {
                    // ajax qr failed. While this is a dupe, most likely the user didn't
                    // see the initial post, so act like it went through.
                    eval(print_standard_redirect('redirect_postthanks', true, true));
                } else {
                    eval(print_standard_redirect('redirect_duplicatepost', true, true));
                }
            }
        }
    }
    if (sizeof($errors) > 0) {
        return;
    }
    $id = $dataman->save();
    if ($type == 'thread') {
        $post['threadid'] = $id;
        $threadinfo =& $dataman->thread;
        $post['postid'] = $dataman->fetch_field('firstpostid');
    } else {
        $post['postid'] = $id;
    }
    $post['visible'] = $dataman->fetch_field('visible');
    $set_open_status = false;
    $set_sticky_status = false;
    if ($vbulletin->GPC['openclose'] and ($threadinfo['postuserid'] != 0 and $threadinfo['postuserid'] == $vbulletin->userinfo['userid'] and $forumperms & $vbulletin->bf_ugp_forumpermissions['canopenclose'] or can_moderate($threadinfo['forumid'], 'canopenclose'))) {
        $set_open_status = true;
    }
    if ($vbulletin->GPC['stickunstick'] and can_moderate($threadinfo['forumid'], 'canmanagethreads')) {
        $set_sticky_status = true;
    }
    if ($set_open_status or $set_sticky_status) {
        $thread =& datamanager_init('Thread', $vbulletin, ERRTYPE_SILENT, 'threadpost');
        if ($type == 'thread') {
            $thread->set_existing($dataman->thread);
            if ($set_open_status) {
                $post['postpoll'] = false;
            }
        } else {
            $thread->set_existing($threadinfo);
        }
        if ($set_open_status) {
            $thread->set('open', $thread->fetch_field('open') == 1 ? 0 : 1);
        }
        if ($set_sticky_status) {
            $thread->set('sticky', $thread->fetch_field('sticky') == 1 ? 0 : 1);
        }
        $thread->save();
    }
    if ($type == 'thread') {
        add_tags_to_thread($threadinfo, $post['taglist']);
    }
    // ### DO THREAD RATING ###
    build_thread_rating($post['rating'], $foruminfo, $threadinfo);
    // ### DO EMAIL NOTIFICATION ###
    if ($post['visible'] and $type != 'thread' and !in_coventry($vbulletin->userinfo['userid'], true)) {
        exec_send_notification($threadinfo['threadid'], $vbulletin->userinfo['userid'], $post['postid']);
    }
    // ### DO THREAD SUBSCRIPTION ###
    if ($vbulletin->userinfo['userid'] != 0) {
        require_once DIR . '/includes/functions_misc.php';
        $post['emailupdate'] = verify_subscription_choice($post['emailupdate'], $vbulletin->userinfo, 9999);
        ($hook = vBulletinHook::fetch_hook('newpost_subscribe')) ? eval($hook) : false;
        if (!$threadinfo['issubscribed'] and $post['emailupdate'] != 9999) {
            // user is not subscribed to this thread so insert it
            /*insert query*/
            $vbulletin->db->query_write("INSERT IGNORE INTO " . TABLE_PREFIX . "subscribethread (userid, threadid, emailupdate, folderid, canview)\n\t\t\t\t\tVALUES (" . $vbulletin->userinfo['userid'] . ", {$threadinfo['threadid']}, {$post['emailupdate']}, {$post['folderid']}, 1)");
        } else {
            // User is subscribed, see if they changed the settings for this thread
            if ($post['emailupdate'] == 9999) {
                // Remove this subscription, user chose 'No Subscription'
                $vbulletin->db->query_write("DELETE FROM " . TABLE_PREFIX . "subscribethread WHERE threadid = {$threadinfo['threadid']} AND userid = " . $vbulletin->userinfo['userid']);
            } else {
                if ($threadinfo['emailupdate'] != $post['emailupdate'] or $threadinfo['folderid'] != $post['folderid']) {
                    // User changed the settings so update the current record
                    /*insert query*/
                    $vbulletin->db->query_write("REPLACE INTO " . TABLE_PREFIX . "subscribethread (userid, threadid, emailupdate, folderid, canview)\n\t\t\t\t\tVALUES (" . $vbulletin->userinfo['userid'] . ", {$threadinfo['threadid']}, {$post['emailupdate']}, {$post['folderid']}, 1)");
                }
            }
        }
    }
    ($hook = vBulletinHook::fetch_hook('newpost_complete')) ? eval($hook) : false;
}
コード例 #2
0
ファイル: threadtag.php プロジェクト: holandacz/nb4
     while ($tag = $db->fetch_array($tags_sql)) {
         if ($tag['userid'] == $vbulletin->userinfo['userid'] or $forumperms & $vbulletin->bf_ugp_forumpermissions['candeletetagown'] and $threadinfo['postuserid'] == $vbulletin->userinfo['userid'] or can_moderate($threadinfo['forumid'], 'caneditthreads')) {
             if (!in_array($tag['tagid'], $vbulletin->GPC['tagskept'])) {
                 $delete[] = $tag['tagid'];
             }
         }
     }
     ($hook = vBulletinHook::fetch_hook('threadtag_domanage_delete')) ? eval($hook) : false;
     if ($delete) {
         $db->query_write("\n\t\t\t\tDELETE FROM " . TABLE_PREFIX . "tagthread\n\t\t\t\tWHERE threadid = {$threadinfo['threadid']}\n\t\t\t\t\tAND tagid IN (" . implode(',', $delete) . ")\n\t\t\t");
         $threadinfo['taglist'] = rebuild_thread_taglist($threadinfo['threadid']);
     }
 }
 ($hook = vBulletinHook::fetch_hook('threadtag_domanage_postdelete')) ? eval($hook) : false;
 if ($vbulletin->GPC['taglist'] and $show['add_option']) {
     $errors = add_tags_to_thread($threadinfo, $vbulletin->GPC['taglist']);
 } else {
     $errors = array();
 }
 if ($vbulletin->GPC['ajax']) {
     $threadinfo = fetch_threadinfo($threadinfo['threadid'], false);
     // get updated tag list
     $tagcount = $threadinfo['taglist'] ? count(explode(',', $threadinfo['taglist'])) : 0;
     require_once DIR . '/includes/class_xml.php';
     $xml = new vB_AJAX_XML_Builder($vbulletin, 'text/xml');
     $xml->add_group('tag');
     $xml->add_tag('taghtml', process_replacement_vars(fetch_tagbits($threadinfo)));
     if ($errors) {
         $errorlist = '';
         foreach ($errors as $error) {
             $errorlist .= "\n   * {$error}";