public function post() { if ($this->_board->isReadOnly()) { $this->error(ECode::$BOARD_READONLY); } if (!$this->_board->hasPostPerm(User::getInstance())) { $this->error(ECode::$BOARD_NOPOST); } $article = false; if (isset($this->params['gid'])) { $reID = (int) $this->params['gid']; if ($this->_board->isNoReply()) { $this->error(ECode::$BOARD_NOREPLY); } try { $article = Article::getInstance($reID, $this->_board); } catch (ArticleNullException $e) { $this->error(ECode::$ARTICLE_NOREID); } if ($article->isNoRe()) { $this->error(ECode::$ARTICLE_NOREPLY); } } else { if ($this->_board->isTmplPost()) { $this->error(ECode::$TMPL_ERROR); } $reID = 0; } $single = isset($this->params['url']['s']) || isset($this->params['form']['s']); if ($this->RequestHandler->isPost()) { if (!isset($this->params['form']['subject'])) { $this->error(ECode::$POST_NOSUB); } if (!isset($this->params['form']['content'])) { $this->error(ECode::$POST_NOCON); } $subject = trim($this->params['form']['subject']); $content = trim($this->params['form']['content']); $subject = nforum_iconv($this->encoding, $this->appEncoding, $subject); $content = nforum_iconv($this->encoding, $this->appEncoding, $content); $subject = rawurldecode($subject); $sig = User::getInstance()->signature; $email = 0; $anony = null; $outgo = 0; if (isset($this->params['form']['email'])) { $email = 1; } if (isset($this->params['form']['anony']) && $this->_board->isAnony()) { $anony = 1; } if (isset($this->params['form']['outgo']) && $this->_board->isOutgo()) { $outgo = 1; } try { if (false === $article) { Article::post($this->_board, $subject, $content, $sig, $email, $anony, $outgo); } else { $article->reply($subject, $content, $sig, $email, $anony, $outgo); } } catch (ArticlePostException $e) { $this->error($e->getMessage()); } $this->redirect($this->_mbase . "/board/" . $this->_board->NAME . ($single ? "/0" : "") . "?m=" . ECode::$POST_OK); } else { $reTitle = $reContent = ""; if ($reID != 0) { $this->notice = "{$this->_board->DESC}-回复"; $reContent = "\n" . $article->getRef(); //remove ref ubb tag $reContent = XUBB::remove($reContent); if (!strncmp($article->TITLE, "Re: ", 4)) { $reTitle = $article->TITLE; } else { $reTitle = "Re: " . $article->TITLE; } } else { $this->notice = "{$this->_board->DESC}-发表"; } } $this->set("single", $single); $this->set("bName", $this->_board->NAME); $this->set("email", true); $this->set("anony", $this->_board->isAnony()); $this->set("outgo", $this->_board->isOutgo()); $this->set("title", (string) $reTitle); $this->set("content", (string) $reContent); $this->set("reid", $reID); }
public function ajax_tmpl() { $article = $this->_postInit(); App::import("vendor", "model/template"); if (!$this->RequestHandler->isPost()) { $this->error(ECode::$SYS_REQUESTERROR); } if (!isset($this->params['form']['tmplid'])) { $this->error(ECode::$TMPL_ERROR); } $id = trim($this->params['form']['tmplid']); try { $t = Template::getInstance($id, $this->_board); } catch (TemplateNullException $e) { $this->error(ECode::$TMPL_ERROR); } $val = $this->params['form']['q']; $val = nforum_iconv('UTF-8', $this->encoding, $val); $pre = $t->getPreview($val); $subject = $pre[0]; $preview = $pre[1]; $content = $pre[2]; if ($this->params['form']['pre'] == "0") { $u = User::getInstance(); try { if (false === $article) { $id = Article::post($this->_board, $subject, $content, $u->signature); } else { $id = $article->reply($subject, $content, $u->signature); } $gid = Article::getInstance($id, $this->_board); $gid = $gid->GROUPID; } catch (ArticlePostException $e) { $this->error($e->getMessage()); } $ret['ajax_code'] = ECode::$POST_OK; $ret['default'] = "/board/" . $this->_board->NAME; $mode = $this->Cookie->read('BMODE'); if ($mode != null && $mode != BOARD::$THREAD) { $ret['default'] .= '/mode/' . $this->Cookie->read('BMODE'); } $ret['list'][] = array("text" => '版面:' . $this->_board->DESC, "url" => $ret['default']); $ret['list'][] = array("text" => '主题:' . str_replace('Re: ', '', $subject), "url" => '/article/' . $this->_board->NAME . '/' . $gid); $ret['list'][] = array("text" => Configure::read("site.name"), "url" => Configure::read("site.home")); $this->set('no_html_data', $ret); } else { App::import('Sanitize'); $subject = Sanitize::html($subject); if (Configure::read("ubb.parse")) { $content = XUBB::parse($content); } $this->set('no_html_data', array("subject" => $subject, "content" => $preview, "reid" => false === $article ? 0 : $article->ID)); } }
public function post() { if (!$this->RequestHandler->isPost()) { $this->error(ECode::$SYS_REQUESTERROR); } if ($this->_board->isReadOnly()) { $this->error(ECode::$BOARD_READONLY); } if (!$this->_board->hasPostPerm(User::getInstance())) { $this->error(ECode::$BOARD_NOPOST); } if (!isset($this->params['form']['title'])) { $this->error(ECode::$POST_NOSUB); } if (!isset($this->params['form']['content'])) { $this->error(ECode::$POST_NOCON); } $title = trim($this->params['form']['title']); $content = trim($this->params['form']['content']); $title = rawurldecode($title); $content = rawurldecode($content); $title = nforum_iconv($this->encoding, $this->appEncoding, $title); $content = nforum_iconv($this->encoding, $this->appEncoding, $content); if (strlen($title) > 60) { $title = nforum_fix_gbk(substr($title, 0, 60)); } $sig = User::getInstance()->signature; $email = 0; $anony = null; $outgo = 0; if (isset($this->params['form']['signature'])) { $sig = intval($this->params['form']['signature']); } if (isset($this->params['form']['email']) && $this->params['form']['email'] == '1') { $email = 1; } if (isset($this->params['form']['anonymous']) && $this->params['form']['anonymous'] == '1' && $this->_board->isAnony()) { $anony = 1; } if (isset($this->params['form']['outgo']) && $this->params['form']['outgo'] == '1' && $this->_board->isOutgo()) { $outgo = 1; } App::import('vendor', "model/article"); try { if (isset($this->params['form']['reid'])) { if ($this->_board->isNoReply()) { $this->error(ECode::$BOARD_NOREPLY); } $reID = intval($this->params['form']['reid']); try { $reArticle = Article::getInstance($reID, $this->_board); } catch (ArticleNullException $e) { $this->error(ECode::$ARTICLE_NOREID); } if ($reArticle->isNoRe()) { $this->error(ECode::$ARTICLE_NOREPLY); } $id = $reArticle->reply($title, $content, $sig, $email, $anony, $outgo); } else { $id = Article::post($this->_board, $title, $content, $sig, $email, $anony, $outgo); } $new = Article::getInstance($id, $this->_board); $wrapper = Wrapper::getInstance(); $this->set('data', $wrapper->article($new, array('content' => true))); } catch (ArticlePostException $e) { $this->error($e->getMessage()); } }