$specialextra = substr($post['message'], $sppos + 3);
            $post['message'] = substr($post['message'], 0, $sppos);
        }
        $message = $post['message'] . "\n\n[b]" . lang('forum/misc', 'postappend_content') . " (" . dgmdate(TIMESTAMP) . "):[/b]\n{$message}";
        if ($sppos) {
            $message .= chr(0) . chr(0) . chr(0) . $specialextra;
        }
        require_once libfile('function/post');
        $bbcodeoff = checkbbcodes($message, 0);
        C::t('forum_post')->update('tid:' . $_G['tid'], $_GET['pid'], array('message' => $message, 'bbcodeoff' => $bbcodeoff));
        showmessage('postappend_add_succeed', "forum.php?mod=viewthread&tid={$post['tid']}&pid={$post['pid']}&page={$_GET['page']}&extra={$_GET['extra']}#pid{$post['pid']}", array('tid' => $post['tid'], 'pid' => $post['pid']));
    } else {
        include template('forum/postappend');
    }
} elseif ($_GET['action'] == 'pubsave') {
    $return = threadpubsave($_G['tid']);
    if ($return > 0) {
        showmessage('post_newthread_succeed', dreferer(), array('coverimg' => ''));
    } elseif ($return == -1) {
        showmessage('post_newthread_mod_succeed', dreferer(), array('coverimg' => ''));
    } elseif ($return == -2) {
        showmessage('post_reply_mod_succeed', dreferer());
    } else {
        showmessage('thread_nonexistence');
    }
} elseif ($_GET['action'] == 'loadsave') {
    $message = ' ';
    $savepost = C::t('forum_post')->fetch(0, $_GET['pid']);
    if ($savepost) {
        $message = $savepost['message'];
        if ($_GET['type']) {
         require_once libfile('function/followcode');
         $feed = C::t('forum_threadpreview')->fetch($_G['tid']);
         if ($feed) {
             C::t('forum_threadpreview')->update($_G['tid'], array('content' => followcode($message, $_G['tid'], $pid, 1000)));
         }
     }
     if ($thread['lastpost'] == $orig['dateline'] && (!$orig['anonymous'] && $thread['lastposter'] == $orig['author'] || $orig['anonymous'] && $thread['lastposter'] == '') && $orig['anonymous'] != $isanonymous) {
         C::t('forum_thread')->update($_G['tid'], array('lastposter' => $isanonymous ? '' : $orig['author']), true);
     }
     if (!$isorigauthor) {
         updatemodworks('EDT', 1);
         require_once libfile('function/misc');
         modlog($thread, 'EDT');
     }
     if ($isfirstpost && $thread['displayorder'] == -4 && empty($_GET['save'])) {
         threadpubsave($thread['tid']);
     }
 } else {
     if (!$_G['setting']['editperdel']) {
         showmessage('post_edit_thread_ban_del', NULL);
     }
     if ($isfirstpost && $thread['replies'] > 0) {
         showmessage($thread['special'] == 3 ? 'post_edit_reward_already_reply' : 'post_edit_thread_already_reply', NULL);
     }
     if ($thread['special'] == 3) {
         if ($thread['price'] < 0 && $thread['dateline'] + 1 == $orig['dateline']) {
             showmessage('post_edit_reward_nopermission', NULL);
         }
     }
     if ($rushreply) {
         showmessage('post_edit_delete_rushreply_nopermission', NULL);
 public function editpost($parameters)
 {
     $this->_init_parameters($parameters);
     $isfirstpost = $this->post['first'] ? 1 : 0;
     $isorigauthor = $this->member['uid'] && $this->member['uid'] == $this->post['authorid'];
     $this->param['audit'] = $this->post['invisible'] == -2 || $this->thread['displayorder'] == -2 ? $this->param['audit'] : 0;
     list($this->param['modnewthreads'], $this->param['modnewreplies']) = threadmodstatus($this->param['subject'] . "\t" . $this->param['message'] . $this->param['extramessage']);
     if ($post_invalid = checkpost($this->param['subject'], $this->param['message'], $isfirstpost && ($this->param['special'] || $this->param['sortid']))) {
         showmessage($post_invalid, '', array('minpostsize' => $this->setting['minpostsize'], 'maxpostsize' => $this->setting['maxpostsize']));
     }
     if (!$isorigauthor && !$this->group['allowanonymous']) {
         if ($this->post['anonymous'] && !$this->param['isanonymous']) {
             $this->param['isanonymous'] = 0;
             $this->param['threadupdatearr']['author'] = $this->post['author'];
             $anonymousadd = 0;
         } else {
             $this->param['isanonymous'] = $this->post['anonymous'];
             $anonymousadd = '';
         }
     } else {
         $this->param['threadupdatearr']['author'] = $this->param['isanonymous'] ? '' : $this->post['author'];
         $anonymousadd = $this->param['isanonymous'];
     }
     if ($isfirstpost) {
         if (trim($this->param['subject']) == '' && $this->thread['special'] != 2) {
             showmessage('post_sm_isnull');
         }
         if (!$this->param['sortid'] && !$this->thread['special'] && trim($this->param['message']) == '') {
             showmessage('post_sm_isnull');
         }
         $publishdate = null;
         if ($this->group['allowsetpublishdate'] && $this->thread['displayorder'] == -4) {
             $cron_publish_ids = dunserialize($this->cache('cronpublish'));
             if (!$this->param['cronpublish'] && in_array($this->thread['tid'], $cron_publish_ids) || $this->param['modnewthreads']) {
                 $this->param['threadupdatearr']['dateline'] = $publishdate = TIMESTAMP;
                 unset($cron_publish_ids[$this->thread['tid']]);
                 $cron_publish_ids = serialize($cron_publish_ids);
                 savecache('cronpublish', $cron_publish_ids);
             } elseif ($this->param['cronpublish'] && $this->param['cronpublishdate']) {
                 $this->param['threadupdatearr']['dateline'] = $publishdate = strtotime($this->param['cronpublishdate']);
                 $this->param['save'] = 1;
                 if (!in_array($this->thread['tid'], $cron_publish_ids)) {
                     $cron_publish_ids[$this->thread['tid']] = $this->thread['tid'];
                     $cron_publish_ids = serialize($cron_publish_ids);
                     savecache('cronpublish', $cron_publish_ids);
                 }
             }
         }
         $this->param['readperm'] = $this->group['allowsetreadperm'] ? intval($this->param['readperm']) : ($isorigauthor ? 0 : 'ignore');
         if ($this->thread['special'] != 3) {
             $this->param['price'] = intval($this->param['price']);
             $this->param['price'] = $this->thread['price'] < 0 && !$this->thread['special'] ? $isorigauthor || !$this->param['price'] ? -1 : $this->param['price'] : ($this->group['maxprice'] ? $this->param['price'] <= $this->group['maxprice'] ? $this->param['price'] > 0 ? $this->param['price'] : 0 : $this->group['maxprice'] : ($isorigauthor ? $this->param['price'] : $this->thread['price']));
             if ($this->param['price'] > 0 && floor($this->param['price'] * (1 - $this->setting['creditstax'])) == 0) {
                 return $this->showmessage('post_net_price_iszero');
             }
         }
         $this->thread['status'] = setstatus(4, $this->param['ordertype'], $this->thread['status']);
         $this->thread['status'] = setstatus(15, $this->param['imgcontent'], $this->thread['status']);
         if ($this->param['imgcontent']) {
             stringtopic($this->param['message'], $this->post['tid'], true, $this->param['imgcontentwidth']);
         }
         $this->thread['status'] = setstatus(2, $this->param['hiddenreplies'], $this->thread['status']);
         $this->thread['status'] = setstatus(6, $this->param['allownoticeauthor'] ? 1 : 0, $this->thread['status']);
         $displayorder = empty($this->param['save']) ? $this->thread['displayorder'] == -4 ? -4 : $this->thread['displayorder'] : -4;
         $this->param['threadupdatearr']['typeid'] = $this->param['typeid'];
         $this->param['threadupdatearr']['sortid'] = $this->param['sortid'];
         $this->param['threadupdatearr']['subject'] = $this->param['subject'];
         if ($this->param['readperm'] !== 'ignore') {
             $this->param['threadupdatearr']['readperm'] = $this->param['readperm'];
         }
         $this->param['threadupdatearr']['price'] = $this->param['price'];
         $this->param['threadupdatearr']['status'] = $this->thread['status'];
         if (getglobal('forum_auditstatuson') && $this->param['audit'] == 1) {
             $this->param['threadupdatearr']['displayorder'] = 0;
             $this->param['threadupdatearr']['moderated'] = 1;
         } else {
             $this->param['threadupdatearr']['displayorder'] = $displayorder;
         }
         C::t('forum_thread')->update($this->thread['tid'], $this->param['threadupdatearr'], true);
         if ($this->thread['tid'] > 1) {
             if ($this->thread['closed'] > 1) {
                 C::t('forum_thread')->update($this->thread['closed'], array('subject' => $this->param['subject']), true);
             } elseif (empty($this->thread['isgroup'])) {
                 $threadclosed = C::t('forum_threadclosed')->fetch($thread['tid']);
                 if ($threadclosed['redirect']) {
                     C::t('forum_thread')->update($threadclosed['redirect'], array('subject' => $this->param['subject']), true);
                 }
             }
         }
         $class_tag = new tag();
         $tagstr = $class_tag->update_field($this->param['tags'], $this->thread['tid'], 'tid', $this->thread);
     } else {
         if ($this->param['subject'] == '' && $this->param['message'] == '' && $this->thread['special'] != 2) {
             showmessage('post_sm_isnull');
         }
     }
     $this->param['htmlon'] = $this->group['allowhtml'] && !empty($this->param['htmlon']) ? 1 : 0;
     if ($this->setting['editedby'] && TIMESTAMP - $this->post['dateline'] > 60 && $this->member['adminid'] != 1) {
         $editor = $this->param['isanonymous'] && $isorigauthor ? lang('forum/misc', 'anonymous') : $this->member['username'];
         $edittime = dgmdate(TIMESTAMP);
         $this->param['message'] = lang('forum/misc', $this->param['htmlon'] ? 'post_edithtml' : (!$this->forum['allowbbcode'] || $this->param['bbcodeoff'] ? 'post_editnobbcode' : 'post_edit'), array('editor' => $editor, 'edittime' => $edittime)) . $this->param['message'];
     }
     $this->param['bbcodeoff'] = checkbbcodes($this->param['message'], !empty($this->param['bbcodeoff']));
     $this->param['smileyoff'] = checksmilies($this->param['message'], !empty($this->param['smileyoff']));
     $tagoff = $isfirstpost ? !empty($tagoff) : 0;
     if (getglobal('forum_auditstatuson') && $this->param['audit'] == 1) {
         C::t('forum_post')->update($this->thread['posttableid'], $this->post['pid'], array('status' => 4), false, false, null, -2, null, 0);
         updatepostcredits('+', $this->post['authorid'], $isfirstpost ? 'post' : 'reply', $this->forum['fid']);
         updatemodworks('MOD', 1);
         updatemodlog($this->thread['tid'], 'MOD');
     }
     $displayorder = $pinvisible = 0;
     if ($isfirstpost) {
         $displayorder = $this->param['modnewthreads'] ? -2 : $this->thread['displayorder'];
         $pinvisible = $this->param['modnewthreads'] ? -2 : (empty($this->param['save']) ? 0 : -3);
     } else {
         $pinvisible = $this->param['modnewreplies'] ? -2 : ($this->thread['displayorder'] == -4 ? -3 : 0);
     }
     $this->param['message'] = preg_replace('/\\[attachimg\\](\\d+)\\[\\/attachimg\\]/is', '[attach]\\1[/attach]', $this->param['message']);
     $this->param['parseurloff'] = !empty($this->param['parseurloff']);
     $setarr = array('message' => $this->param['message'], 'usesig' => $this->param['usesig'], 'htmlon' => $this->param['htmlon'], 'bbcodeoff' => $this->param['bbcodeoff'], 'parseurloff' => $this->param['parseurloff'], 'smileyoff' => $this->param['smileyoff'], 'subject' => $this->param['subject'], 'tags' => $tagstr, 'port' => getglobal('remoteport'));
     $setarr['status'] = $this->post['status'];
     if ($this->param['modstatus']) {
         foreach ($this->param['modstatus'] as $modbit => $modvalue) {
             $setarr['status'] = setstatus($modbit, $modvalue, $setarr['status']);
         }
     }
     if ($anonymousadd !== '') {
         $setarr['anonymous'] = $anonymousadd;
     }
     if ($publishdate) {
         $setarr['dateline'] = $publishdate;
     }
     if (getglobal('forum_auditstatuson') && $this->param['audit'] == 1) {
         $setarr['invisible'] = 0;
     } else {
         $setarr['invisible'] = $pinvisible;
     }
     C::t('forum_post')->update('tid:' . $this->thread['tid'], $this->post['pid'], $setarr);
     $this->forum['lastpost'] = explode("\t", $this->forum['lastpost']);
     if ($this->post['dateline'] == $this->forum['lastpost'][2] && ($this->post['author'] == $this->forum['lastpost'][3] || $this->forum['lastpost'][3] == '' && $this->post['anonymous'])) {
         $lastpost = $this->thread['tid'] . "\t" . ($isfirstpost ? $this->param['subject'] : $this->thread['subject']) . "\t" . $this->post['dateline'] . "\t" . ($this->param['isanonymous'] ? '' : $this->post['author']);
         C::t('forum_forum')->update($this->forum['fid'], array('lastpost' => $lastpost));
     }
     if (!getglobal('forum_auditstatuson') || $this->param['audit'] != 1) {
         if ($isfirstpost && $this->param['modnewthreads']) {
             C::t('forum_thread')->update($this->thread['tid'], array('displayorder' => -2));
             manage_addnotify('verifythread');
         } elseif (!$isfirstpost && $this->param['modnewreplies']) {
             C::t('forum_thread')->increase($this->thread['tid'], array('replies' => -1));
             manage_addnotify('verifypost');
         }
         if ($this->param['modnewreplies'] || $this->param['modnewthreads']) {
             C::t('forum_forum')->update($this->forum['fid'], array('modworks' => '1'));
         }
     }
     if ($this->thread['lastpost'] == $this->post['dateline'] && (!$this->post['anonymous'] && $this->thread['lastposter'] == $this->post['author'] || $this->post['anonymous'] && $this->thread['lastposter'] == '') && $this->post['anonymous'] != $this->param['isanonymous']) {
         C::t('forum_thread')->update($this->thread['tid'], array('lastposter' => $this->param['isanonymous'] ? '' : $this->post['author']), true);
     }
     if (!$isorigauthor) {
         updatemodworks('EDT', 1);
         require_once libfile('function/misc');
         modlog($this->thread, 'EDT');
     }
     if ($isfirstpost && $this->thread['displayorder'] == -4 && empty($this->param['save'])) {
         threadpubsave($this->thread['tid']);
     }
 }
 *      $Id: cron_publish_halfhourly.php 31463 2012-08-30 08:59:17Z zhangguosheng $
 */
if (!defined('IN_DISCUZ')) {
    exit('Access Denied');
}
require_once libfile('function/forum');
require_once libfile('function/post');
loadcache('cronpublish');
$dataChanged = false;
$cron_publish_ids = array();
$cron_publish_ids = unserialize(getglobal('cache/cronpublish'));
if (count($cron_publish_ids) > 0) {
    $threadall = C::t('forum_thread')->fetch_all_by_tid($cron_publish_ids);
    foreach ($cron_publish_ids as $tid) {
        if (!$threadall[$tid]) {
            unset($cron_publish_ids[$tid]);
            $dataChanged = true;
        }
    }
    foreach ($threadall as $stid => $sdata) {
        if ($sdata['dateline'] <= getglobal('timestamp')) {
            threadpubsave($stid, true);
            unset($cron_publish_ids[$stid]);
            $dataChanged = true;
        }
    }
    if ($dataChanged === true) {
        $newcronpublish = serialize($cron_publish_ids);
        savecache('cronpublish', $newcronpublish);
    }
}