/** * function render * call subclass _render * check rendered & do encoding convert * if using smarty: * render a tpl via $action and $path, return html * $path is base on VIEWS * else: * the params is no use * * @param string $action * @param string $path * @return string * @access public */ public function render($action = null, $path = null) { $this->_out = $this->_render($action, $path); //IGNORE $this->_out = nforum_iconv(Configure::read("App.encoding"), $this->encoding, $this->_out, 2); return $this->_out; }
/** * @override method */ public function afterFilter() { if ($this->RequestHandler->isFlash()) { $this->output = nforum_iconv($this->encoding, 'utf-8', $this->output); } if ($this->html) { if ($this->spider) { if (!$this->front) { $this->output = $this->view->render('header', '') . $this->output . $this->view->render('footer', ''); } } else { if (!$this->front) { $this->output = $this->view->render('css', '') . $this->output . $this->view->render('script', ''); } } } if (Configure::read() >= 2) { $this->output .= $this->_getDump(); } if (Configure::read() == 3) { $this->output .= $this->_getDebug(); } if (Configure::read() == 3) { $this->output .= $this->_getDebug(); } }
public function threads() { App::import('vendor', array('model/board', 'model/threads', 'inc/pagination')); $day = 7; $title1 = $title2 = $title3 = $author = ''; if (isset($this->params['url']['title1'])) { $title1 = nforum_iconv($this->encoding, $this->appEncoding, rawurldecode(trim($this->params['url']['title1']))); } if (isset($this->params['url']['title2'])) { $title2 = nforum_iconv($this->encoding, $this->appEncoding, rawurldecode(trim($this->params['url']['title2']))); } if (isset($this->params['url']['titlen'])) { $title3 = nforum_iconv($this->encoding, $this->appEncoding, rawurldecode(trim($this->params['url']['titlen']))); } if (isset($this->params['url']['author'])) { $author = trim($this->params['url']['author']); } if (isset($this->params['url']['day'])) { $day = intval($this->params['url']['day']); } $m = isset($this->params['url']['m']) && $this->params['url']['m'] == '1'; $a = isset($this->params['url']['a']) && $this->params['url']['a'] == '1'; $return = Configure::read('search.max'); $res = array(); if (!isset($this->params['url']['board'])) { $this->error(ECode::$BOARD_UNKNOW); } $board = $this->params['url']['board']; try { $brd = Board::getInstance($board); $res = array_merge($res, Threads::search($brd, $title1, $title2, $title3, $author, $day, $m, $a, $return)); } catch (BoardNullException $e) { } $count = isset($this->params['url']['count']) ? $this->params['url']['count'] : Configure::read("pagination.threads"); if (($count = intval($count)) <= 0) { $count = Configure::read("pagination.threads"); } if ($count > Configure::read('plugins.api.page_item_limit')) { $count = Configure::read("pagination.threads"); } $page = isset($this->params['url']['page']) ? $this->params['url']['page'] : 1; $page = intval($page); $pagination = new Pagination(new ArrayPageableAdapter($res), $count); $articles = $pagination->getPage($page); $wrapper = Wrapper::getInstance(); $data = array(); $data['pagination'] = $wrapper->page($pagination); foreach ($articles as $v) { $data['threads'][] = $wrapper->article($v, array('threads' => true)); } $this->set('data', $data); }
public function add() { if (!$this->RequestHandler->isPost()) { $this->error(ECode::$SYS_REQUESTERROR); } if (!isset($this->params['form']['dir']) || !isset($this->params['form']['name'])) { $this->error(); } $dir = $this->params['form']['dir'] == '1'; $val = trim($this->params['form']['name']); $level = $this->params['num']; try { $fav = Favor::getInstance($level); } catch (FavorNullException $e) { $this->error(ECode::$USER_FAVERROR); } if ($val == "") { $this->error(); } if ($dir) { $val = nforum_iconv($this->encoding, $this->appEncoding, $val); if (!$fav->add($val, Favor::$DIR)) { $this->error(); } } else { App::import("vendor", "model/board"); try { $val = Board::getInstance($val); if (!$fav->add($val, Favor::$BOARD)) { $this->error(); } } catch (BoardNullException $e) { $this->error(ECode::$Board_UNKNOW); } } try { $fav = Favor::getInstance($level); } catch (FavorNullException $e) { $this->error(ECode::$USER_FAVERROR); } $this->set('data', $this->_favor($fav)); }
public function searchBoard() { $bName = ""; if (isset($this->params['url']['name'])) { $bName = trim($this->params['url']['name']); } $bName = nforum_iconv($this->encoding, $this->appEncoding, $bName); $boards = Board::search($bName); if (count($boards) == 1) { $this->redirect($this->_mbase . "/board/" . $boards[0]->NAME); } else { $ret = false; foreach ($boards as $b) { $ret[] = array("name" => $b->DESC, "desc" => $b->NAME, "url" => ($b->isDir() ? "/section/" : "/board/") . $b->NAME, "dir" => $b->isDir()); } $this->set("boards", $ret); $this->set("parent", false); $this->autoRender = false; $this->render("index", "/section/"); } }
public function ajax_form() { if (!$this->RequestHandler->isPost()) { $this->error(ECode::$SYS_REQUESTERROR); } $this->requestLogin(); @($auth = $this->params['form']['auth']); @($phone = trim($this->params['form']['phone'])); @($tname = trim($this->params['form']['tname'])); @($gender = trim($this->params['form']['gender'])); @($dept = trim($this->params['form']['dept'])); @($address = trim($this->params['form']['address'])); @($year = trim($this->params['form']['year'])); @($month = trim($this->params['form']['month'])); @($day = trim($this->params['form']['day'])); @($email = trim($this->params['form']['email'])); if (!$this->AuthImg->check($auth)) { $this->error(ECode::$REG_AUTH); } $this->AuthImg->destory(); if (!preg_match("/^\\w+([-+.]\\w+)*@\\w+([-.]\\w)*\\.\\w+([-.]\\w+)*/", $email) || $tname == "" || $gender == "" || $dept == "" || $address == "" || $year == "" || $month == "" || $day == "") { $this->error(ECode::$REG_FORMAT); } if (!preg_match("/^[0-9()-]+\$/", $phone)) { $this->error(ECode::$REG_AUTH); } if ($gender != '1' && $gender != '2') { $gender = 1; } if (!preg_match("/^(19|20)[0-9]{2}\$/", $year)) { $year = "1970"; } if ($month == "" || intval($month) < 1 || intval($month) > 12) { $month = "01"; } if ($day == "" || intval($day) < 1 || intval($day) > 31) { $day = "01"; } $birthday = "{$year}-{$month}-{$day}"; $tname = nforum_iconv('utf-8', $this->encoding, $tname); $dept = nforum_iconv('utf-8', $this->encoding, $dept); $address = nforum_iconv('utf-8', $this->encoding, $address); try { $u = User::getInstance(); $u->reg($tname, $dept, $address, $gender, $year, $month, $day, $email, $phone, '', false); } catch (UserNullException $e) { $this->error(ECode::$USER_NOID); } catch (UserRegException $e) { $this->error($e->getMessage()); } $ret['ajax_code'] = ECode::$REG_FORMOK; $ret['default'] = Configure::read("site.home"); $ret['list'][] = array("text" => Configure::read("site.name"), "url" => Configure::read("site.home")); $this->set('no_html_data', $ret); }
public function ajax_add() { if (!$this->RequestHandler->isPost()) { $this->error(ECode::$SYS_REQUESTERROR); } $this->requestLogin(); $db = DB::getInstance(); $u = User::getInstance(); if (!$u->isAdmin()) { $sql = "select count(*) as num from pl_vote where status=1 and start>=? and uid=?"; $res = $db->one($sql, array(strtotime(date("Y-m-d", time())), $u->userid)); if ($res !== false && $res['num'] >= 2) { $this->error("每天你最多开启两次投票"); } } $subject = @trim($this->params['form']['subject']); $desc = @trim($this->params['form']['desc']); $end = @trim($this->params['form']['end']); $type = @trim($this->params['form']['type']); $limit = @trim($this->params['form']['limit']); $result_voted = isset($this->params['form']['result_voted']) ? 1 : 0; if (empty($subject) || empty($end)) { $this->error(); } if ($type != "0" && $type != "1") { $type = 0; } if (empty($limit) || intval($limit) < 2 || intval($limit) > 19) { $limit = 0; } if (strtotime($end) === false || !preg_match("/\\d{4}(-\\d{2}){2}/", $end)) { $this->error("截止日期错误"); } $items = array(); foreach ($this->params['form'] as $k => $v) { if (preg_match('/^i\\d+$/', $k) && trim($v) != "") { $items[] = nforum_iconv('UTF-8', $this->encoding, trim($v)); } } $realNum = count($items); if ($realNum < 2 || $realNum > 20) { $this->error("选项数量错误,发起投票失败"); } if ($limit > $realNum) { $limit = $realNum; } $subject = nforum_iconv('UTF-8', $this->encoding, $subject); $desc = nforum_iconv('UTF-8', $this->encoding, $desc); $vid = Vote::add($u->userid, $subject, $desc, strtotime($end), $type, $limit, $items, $result_voted); $site = Configure::read("site"); $a_title = $subject; $a_content = "主题:{$subject}\n描述:{$desc}\n发起人:{$u->userid}\n类型:" . ($type == 0 ? '单选' : '多选') . "\n截止日期:{$end}\n链接:[url={$site['domain']}{$site['prefix']}/vote/view/{$vid}]{$site['domain']}{$site['prefix']}/vote/view/{$vid}[/url]\n[vote={$vid}][/vote]"; App::import("vendor", "model/article"); $aid = Article::autoPost($this->_board, $a_title, $a_content); $db->update("pl_vote", array("aid" => $aid), "where vid=?", array($vid)); if (isset($this->params['form']['b'])) { App::import("vendor", "model/board"); try { $board = Board::getInstance(trim($this->params['form']['b'])); if ($board->hasPostPerm($u)) { Article::autoPost($board->NAME, '[投票]' . $a_title, $a_content); } } catch (Exception $e) { } } $ret['ajax_code'] = "发起投票成功"; $ret['default'] = "/vote?c=list&u=" . $u->userid; $ret['list'][] = array("text" => '我的投票', "url" => "/vote?c=list&u=" . $u->userid); $ret['list'][] = array("text" => '热门投票', "url" => "/vote?c=hot"); $this->set('no_html_data', $ret); }
public function reply() { if (!$this->RequestHandler->isPost()) { $this->error(ECode::$SYS_REQUESTERROR); } if (!isset($this->params['type'])) { $this->error(ECode::$MAIL_NOBOX); } if (!isset($this->params['num'])) { $this->error(ECode::$MAIL_NOMAIL); } $type = $this->params['type']; $num = $this->params['num']; @($title = strval(trim($this->params['form']['title']))); @($content = strval(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); $sig = User::getInstance()->signature; $bak = $u->getCustom("mailbox_prop", 0); if (isset($this->params['form']['signature'])) { $sig = intval($this->params['form']['signature']); } if (isset($this->params['form']['backup']) && $this->params['form']['backup'] == 1) { $bak = 1; } try { $box = new MailBox(User::getInstance(), $type); $mail = Mail::getInstance($num, $box); $mail->reply($title, $content, $sig, $bak); $wrapper = Wrapper::getInstance(); $data = $wrapper->mail($mail); } catch (MailBoxNullException $e) { $this->error(ECode::$MAIL_NOBOX); } catch (MailNullException $e) { $this->error(ECode::$MAIL_NOMAIL); } catch (MailSendException $e) { $this->error($e->getMessage()); } $this->set('data', $data); }
public function ajax_change() { if (!isset($this->params['form']['ac']) || !isset($this->params['form']['v'])) { $this->error(); } $action = $this->params['form']['ac']; $val = $this->params['form']['v']; $level = $this->params['num']; try { $fav = Favor::getInstance($level); } catch (FavorNullException $e) { $this->error(ECode::$USER_FAVERROR); } if ($val == "") { $this->error(); } switch ($action) { case "ab": try { $val = Board::getInstance($val); if (!$fav->add($val, Favor::$BOARD)) { $this->error(); } } catch (Exception $e) { $this->error(ECode::$BOARD_UNKNOW); } break; case "ad": if (!$fav->add(nforum_iconv("utf-8", $this->encoding, $val), Favor::$DIR)) { $this->error(); } break; case "db": try { $val = Board::getInstance($val); if (!$fav->delete($val, Favor::$BOARD)) { $this->error(); } } catch (Exception $e) { $this->error(ECode::$BOARD_UNKNOW); } break; case "dd": if (!$fav->delete($val, Favor::$DIR)) { $this->error(); } break; } }
public function edit() { if ($this->_board->isReadOnly()) { $this->error(ECode::$BOARD_READONLY); } if (!$this->_board->hasPostPerm(User::getInstance())) { $this->error(ECode::$BOARD_NOPOST); } if (!isset($this->params['gid'])) { $this->error(ECode::$ARTICLE_NONE); } $id = (int) $this->params['gid']; try { $article = Article::getInstance($id, $this->_board); } catch (ArticleNullException $e) { $this->error(ECode::$ARTICLE_NONE); } if (!$article->hasEditPerm(User::getInstance())) { $this->error(ECode::$ARTICLE_NOEDIT); } $single = isset($this->params['url']['s']) || isset($this->params['form']['s']); if ($this->RequestHandler->isPost()) { $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); if (!$article->update($subject, $content)) { $this->error(ECode::$ARTICLE_EDITERROR); } $this->redirect($this->_mbase . "/board/" . $this->_board->NAME . ($single ? "/0" : "") . "?m=" . ECode::$ARTICLE_EDITOK); } else { $this->notice = "{$this->_board->DESC}-编辑"; $title = $article->TITLE; $content = $article->getContent(); } $this->set("bName", $this->_board->NAME); $this->set("email", false); $this->set("anony", false); $this->set("outgo", false); $this->set("title", $title); $this->set("content", $content); $this->set("single", $single); $this->set("reid", $id); $this->set("edit", true); $this->autoRender = false; $this->render("post"); }
public function update() { 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['id'])) { $this->error(ECode::$ARTICLE_NONE); } $id = intval($this->params['id']); try { App::import('vendor', "model/article"); $article = Article::getInstance($id, $this->_board); } catch (ArticleNullException $e) { $this->error(ECode::$ARTICLE_NONE); } $u = User::getInstance(); if (!$article->hasEditPerm($u)) { $this->error(ECode::$ARTICLE_NOEDIT); } 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)); } if (!$article->update($title, $content)) { $this->error(ECode::$ARTICLE_EDITERROR); } $new = Article::getInstance($id, $this->_board); $wrapper = Wrapper::getInstance(); $this->set('data', $wrapper->article($new, array('content' => true))); }
public function ajax_moddeny() { if (!$this->RequestHandler->isPost()) { $this->error(ECode::$SYS_REQUESTERROR); } $this->requestLogin(); $u = User::getInstance(); if (!isset($this->params['form']['id'])) { $this->error(ECode::$DENY_NOID); } if (!isset($this->params['form']['reason'])) { $this->error(ECode::$DENY_NOREASON); } if (!isset($this->params['form']['day'])) { $this->error(ECode::$DENY_INVALIDDAY); } $id = $this->params['form']['id']; $reason = nforum_iconv('utf-8', $this->encoding, $this->params['form']['reason']); $day = intval($this->params['form']['day']); if ($day < 1) { $this->error(ECode::$DENY_INVALIDDAY); } try { $this->_board->modDeny($id, $reason, $day); } catch (BoardDenyException $e) { $this->error($e->getMessage()); } $ret['ajax_code'] = ECode::$SYS_AJAXOK; $ret['default'] = '/board/' . $this->_board->NAME . '/denylist'; $ret['list'][] = array('text' => '版面封禁列表:' . $this->_board->DESC, 'url' => '/board/' . $this->_board->NAME . '/denylist'); $ret['list'][] = array('text' => '版面:' . $this->_board->DESC, 'url' => '/board/' . $this->_board->NAME); $ret['list'][] = array("text" => Configure::read("site.name"), "url" => Configure::read("site.home")); $this->set('no_html_data', $ret); }
public function ajax_list() { $this->requestLogin(); if (!isset($this->params['url']['t'])) { $this->error(); } $type = $this->params['url']['t']; if (!isset($this->params['url']['tt'])) { $this->error(); } $ret = array(); try { $widgets = Widget::wGet(User::getInstance()); $my = array(); foreach ($widgets as $v) { $my[] = $v["name"]; } switch ($type) { case 'section': //$tt is for 0:root or 1:dir $tt = $this->params['url']['tt']; if ($tt != 0 && $tt != 1) { $this->error(); } $secs = Configure::read('section'); foreach ($secs as $k => $v) { $w = Widget::getInstance("section-" . $k); if ($tt == 0) { if (!in_array($w->wGetName(), $my)) { $title = $w->wGetTitle(); $title = $title["text"]; $ret[] = array('wid' => $w->wGetName(), 'title' => $title, 'p' => file_exists(IMAGES . 'app/icon/' . $w->wGetName() . '.png') ? $w->wGetName() : "default"); } } else { if ($tt == 1) { foreach ($w->getDir() as $dir) { $ww = Widget::getInstance("section-" . $dir->NAME); if (!in_array($ww->wGetName(), $my)) { $title = $ww->wGetTitle(); $title = $title["text"]; $ret[] = array('wid' => $ww->wGetName(), 'title' => $title, 'p' => file_exists(IMAGES . 'app/icon/' . $ww->wGetName() . '.png') ? $ww->wGetName() : "default"); } } } } } break; case 'favor': //tt is for favor level //favor is only one level!!! the structure error!!! $tt = intval($this->params['url']['tt']); $favor = Favor::getInstance($tt); if (!in_array($favor->wGetName(), $my)) { $title = $favor->wGetTitle(); $title = $title["text"]; $ret[] = array('wid' => $favor->wGetName(), 'title' => $title, 'p' => file_exists(IMAGES . 'app/icon/' . $favor->wGetName() . '.png') ? $favor->wGetName() : "default"); } foreach ($favor->getDir() as $w) { if (!in_array("favor-" . $w->BID, $my) && $w->NAME == "") { $ret[] = array('wid' => "favor-" . $w->BID, 'title' => $w->DESC, 'p' => "default"); } } break; case 'board': if (!isset($this->params['url']['tt'])) { $this->error(); } //$tt is for section num $tt = intval($this->params['url']['tt']); $secs = Configure::read('section'); if (!in_array($tt, array_keys($secs))) { $this->error(); } $w = Section::getInstance($tt, Section::$ALL); foreach ($w->getList() as $brd) { $ww = Widget::getInstance("board-" . $brd->NAME); if (!in_array($ww->wGetName(), $my)) { $title = $ww->wGetTitle(); $title = $title["text"]; $ret[] = array('wid' => $ww->wGetName(), 'title' => $title, 'p' => file_exists(IMAGES . 'app/icon/' . $ww->wGetName() . '.png') ? $ww->wGetName() : "default"); } } break; case 'ext': if (!isset($this->params['url']['tt'])) { $this->error(); } //$tt is for category $tt = $this->params['url']['tt']; $ext = Configure::read('widget.ext'); if (!in_array($tt, array_keys($ext))) { $this->error(); } foreach ($ext[$tt][1] as $v) { try { $w = Widget::getInstance($v); } catch (WidgetNullException $e) { continue; } if (!in_array($w->wGetName(), $my)) { $title = $w->wGetTitle(); $title = $title["text"]; $ret[] = array('wid' => $w->wGetName(), 'title' => $title, "p" => file_exists(IMAGES . 'app/icon/' . $w->wGetName() . '.png') ? $w->wGetName() : "default"); } } break; case 'search': if (!isset($this->params['url']['tt'])) { $this->error(); } //$tt is for widget name $tt = urldecode(urldecode($this->params['url']['tt'])); $tt = nforum_iconv('utf-8', $this->encoding, $tt); $ext = Configure::read('widget.ext'); foreach ($ext as $v) { foreach ($v[1] as $wid) { try { $w = Widget::getInstance($wid); } catch (WidgetNullException $e) { continue; } $title = $w->wGetTitle(); $title = $title["text"]; if (!in_array($w->wGetName(), $my) && strpos($title, $tt) !== false) { $ret[] = array('wid' => $w->wGetName(), 'title' => $title, "p" => file_exists(IMAGES . 'app/icon/' . $w->wGetName() . '.png') ? $w->wGetName() : "default"); } } } break; } } catch (Exception $e) { $this->error(); } $this->set('no_html_data', $ret); //no ajax status info $this->set('no_ajax_info', true); }
public function main() { $week = array("日", "一", "二", "三", "四", "五", "六"); $date[] = "周" . $week[intval(date("w"))]; $date[] = "周" . $week[intval(date("w", time() + 24 * 60 * 60))]; $date[] = "周" . $week[intval(date("w", time() + 2 * 24 * 60 * 60))]; $file = "http://php.weather.sina.com.cn/xml.php?city=%B1%B1%BE%A9&password=DJOYnieT8234jlsK&day="; $res = ""; for ($j = 0; $j <= 2; $j++) { $data = file_get_contents($file . $j); $xml_parser = xml_parser_create(); xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($xml_parser, $data, $vals); xml_parser_free($xml_parser); //print_r($vals); $encoding = Configure::read("App.encoding"); for ($i = 0; $i <= count($vals) - 1; $i++) { if ($vals[$i]['tag'] == "status1" && $vals[$i]['type'] == "complete") { $curStatB = nforum_iconv("utf-8", $encoding, $vals[$i]['value']); } if ($vals[$i]['tag'] == "status2" && $vals[$i]['type'] == "complete") { $curStatE = nforum_iconv("utf-8", $encoding, $vals[$i]['value']); } if ($vals[$i]['tag'] == "temperature1" && $vals[$i]['type'] == "complete") { $curTemp1 = $vals[$i]['value']; } if ($vals[$i]['tag'] == "temperature2" && $vals[$i]['type'] == "complete") { $curTemp2 = $vals[$i]['value']; } if ($vals[$i]['tag'] == "power1" && $vals[$i]['type'] == "complete") { $curWind1 = nforum_iconv("utf-8", $encoding, $vals[$i]['value']); } if ($vals[$i]['tag'] == "power2" && $vals[$i]['type'] == "complete") { $curWind2 = nforum_iconv("utf-8", $encoding, $vals[$i]['value']); } if ($vals[$i]['tag'] == "zwx_l" && $vals[$i]['type'] == "complete") { $zwx = nforum_iconv("utf-8", $encoding, $vals[$i]['value']); } if ($vals[$i]['tag'] == "Weather" && $vals[$i]['type'] == "open") { $curDate = ""; $curStatB = ""; $curStatE = ""; $curTemp1 = ""; $curTemp2 = ""; $img = ""; $curWind1 = ""; $curWind2 = ""; $zwx = ""; } if ($vals[$i]['tag'] == "Weather" && $vals[$i]['type'] == "close") { $img = $this->st2img($curStatB); if ($curStatB != $curStatE) { $curStatB .= "转" . $curStatE; $img .= "" . $this->st2img($curStatE); } if ($curWind1 != $curWind2) { $curWind1 .= "至" . $curWind2 . "级"; } else { $curWind1 .= "级"; } $res .= "|" . $date[$j] . " " . $curStatB . " " . $curTemp1 . "℃-" . $curTemp2 . "℃" . "&风力:" . $curWind1 . (empty($zwx) ? "" : " 紫外线:" . $zwx) . "#" . $img; } } } nforum_cache_write('weather_day', substr($res, 1)); }
/** * change encoding of string * @param string $from * @param string $to * @param mixed $in * @param int $param 0:'',1:'TRANSLIT',2:'IGNORE' * @return string */ function nforum_iconv($from, $to, $in, $param = 1) { if (is_array($in)) { foreach ($in as &$v) { $v = nforum_iconv($from, $to, $v, $param); } return $in; } if (!is_string($in)) { return $in; } $from = strtoupper($from); $to = strtoupper($to); if ($from == $to) { return $in; } $charset = array('UTF-8', 'GBK', 'GB2312'); $params = array('', '//TRANSLIT', '//IGNORE'); $param = isset($params[$param]) ? $params[$param] : $params[1]; if (!in_array($from, $charset) || !in_array($to, $charset)) { return $str; } return @iconv($from, $to . $param, $in); }
public function ajax_delete() { if (!$this->RequestHandler->isPost() && !$this->RequestHandler->isDelete()) { $this->error(ECode::$SYS_REQUESTERROR); } $this->_attOpInit(); $this->brief = true; $u = User::getInstance(); if (isset($this->params['url']['name'])) { $attName = nforum_iconv('utf-8', $this->encoding, $this->params['url']['name']); try { if (isset($this->params['id'])) { $id = $this->params['id']; $article = Article::getInstance($id, $this->_board); if (!$article->hasEditPerm($u)) { $this->error(ECode::$ARTICLE_NOEDIT); } $attNum = 0; foreach ($article->getAttList() as $k => $v) { if ($v['name'] == $attName) { $attNum = intval($k + 1); break; } } $article->delAttach($attNum); $this->set("postUrl", "/{$article->ID}"); } else { Forum::delAttach($attName); } $this->set('ajax_code', ECode::$ATT_DELOK); } catch (ArchiveAttException $e) { $this->error($e->getMessage()); } catch (AttException $e) { $this->error($e->getMessage()); } catch (Exception $e) { $this->error(ECode::$ATT_NAMEERROR); } } else { $this->error(ECode::$ATT_NAMEERROR); } }
public function send() { if (!Mail::canSend()) { $this->error(ECode::$MAIL_SENDERROR); } $u = User::getInstance(); $mail = false; if (isset($this->params['type']) && isset($this->params['num'])) { $type = $this->params['type']; $num = $this->params['num']; try { $mail = MAIL::getInstance($num, new MailBox($u, $type)); } catch (Exception $e) { } } if ($this->RequestHandler->isPost()) { $title = $content = ''; $sig = User::getInstance()->signature; if (isset($this->params['form']['title'])) { $title = trim($this->params['form']['title']); } if (isset($this->params['form']['content'])) { $content = $this->params['form']['content']; } $sig = 0; $bak = isset($this->params['form']['backup']) ? 1 : 0; $title = nforum_iconv($this->encoding, $this->appEncoding, $title); $content = nforum_iconv($this->encoding, $this->appEncoding, $content); try { if (false === $mail) { //send new if (!isset($this->params['form']['id'])) { $this->error(ECode::$POST_NOID); } $id = trim($this->params['form']['id']); Mail::send($id, $title, $content, $sig, $bak); $this->redirect($this->_mbase . "/mail?m=" . ECode::$MAIL_SENDOK); } else { //reply $mail->reply($title, $content, $sig, $bak); $this->redirect($this->_mbase . "/mail/{$type}?m=" . ECode::$MAIL_SENDOK); } } catch (MailSendException $e) { $this->error($e->getMessage()); } } $uid = $title = $content = ""; if (isset($this->params['type']) && isset($this->params['num'])) { $this->notice = "邮件-回复邮件"; if (false === $mail) { //reply article try { $b = Board::getInstance($type); if (!$b->hasReadPerm($u)) { $this->error(ECode::$BOARD_NOPERM); } $mail = Article::getInstance($num, $b); } catch (Exception $e) { $this->error(ECode::$MAIL_NOMAIL); } } if (!strncmp($mail->TITLE, "Re: ", 4)) { $title = $mail->TITLE; } else { $title = "Re: " . $mail->TITLE; } $content = "\n" . $mail->getRef(); //remove ref ubb tag $content = XUBB::remove($content); $uid = $mail->OWNER; } else { $this->notice = "邮件-新邮件"; } $this->set("uid", $uid); $this->set("title", $title); $this->set("content", $content); $this->set("bak", $u->getCustom("mailbox_prop", 0)); }
public function ajax_deny() { if (!$this->RequestHandler->isPost()) { $this->error(ECode::$SYS_REQUESTERROR); } if (!isset($this->params['id'])) { $this->error(ECode::$ARTICLE_NONE); } if (!isset($this->params['form']['reason'])) { $this->error(ECode::$DENY_NOREASON); } if (!isset($this->params['form']['day'])) { $this->error(ECode::$DENY_INVALIDDAY); } $id = $this->params['id']; $reason = nforum_iconv('utf-8', $this->encoding, $this->params['form']['reason']); $day = intval($this->params['form']['day']); if ($day < 1) { $this->error(ECode::$DENY_INVALIDDAY); } $u = User::getInstance(); if (!($u->isBM($this->_board) || $u->isAdmin())) { $this->error(ECode::$ARTICLE_NOMANAGE); } try { $article = Article::getInstance($id, $this->_board); $article->addDeny($reason, $day); } catch (ArticleNullException $e) { $this->error(ECode::$ARTICLE_NONE); } catch (ArticleManageException $e) { $this->error($e->getMessage()); } catch (BoardDenyException $e) { $this->error($e->getMessage()); } }
public function board() { $this->css[] = "board.css"; $this->js[] = "forum.board.js"; $this->notice[] = array("url" => "", "text" => "ËÑË÷½á¹û"); App::import('Sanitize'); $b = isset($this->params['url']['b']) ? $this->params['url']['b'] : ""; $ret = false; $b = trim(rawurldecode($b)); $b = nforum_iconv('utf-8', $this->encoding, $b); $boards = Board::search($b); if (count($boards) == 1) { $this->redirect("/board/" . $boards[0]->NAME); } foreach ($boards as $brd) { $threads = $brd->getTypeArticles(0, 1, Board::$ORIGIN); if (!empty($threads)) { $threads = $threads[0]; $last = array("id" => $threads->ID, "title" => Sanitize::html($threads->TITLE), "owner" => $threads->isSubject() ? $threads->OWNER : "ÔÌûÒÑɾ³ý", "date" => date("Y-m-d H:i:s", $threads->POSTTIME)); } else { $last["id"] = ""; $last["title"] = $last["owner"] = $last["date"] = "ÎÞ"; } $bms = split(" ", $brd->BM); foreach ($bms as &$bm) { if (preg_match("/[^0-9a-zA-Z]/", $bm)) { $bm = array($bm, false); } else { $bm = array($bm, true); } } $ret[] = array("name" => $brd->NAME, "desc" => $brd->DESC, "type" => $brd->isDir() ? "section" : "board", "bms" => $bms, "curNum" => $brd->CURRENTUSERS, "todayNum" => $brd->getTodayNum(), "threadsNum" => $brd->getThreadsNum(), "articleNum" => $brd->ARTCNT, "last" => $last); } $this->set("sec", $ret); $this->set("noBrd", ECode::msg(ECode::$SEC_NOBOARD)); $this->render("index", "section/"); }
public function ajax_preview() { App::import('Sanitize'); if (!isset($this->params['form']['title']) || !isset($this->params['form']['content'])) { $this->error(); } $subject = rawurldecode(trim($this->params['form']['title'])); $subject = nforum_iconv('utf-8', $this->encoding, $subject); if (strlen($subject) > 60) { $subject = nforum_fix_gbk(substr($subject, 0, 60)); } $subject = Sanitize::html($subject); $content = $this->params['form']['content']; $content = nforum_iconv('utf-8', $this->encoding, $content); $content = preg_replace("/\n/", "<br />", Sanitize::html($content)); if (Configure::read("ubb.parse")) { $content = XUBB::parse($content); } $this->set('no_html_data', array("subject" => $subject, "content" => $content)); }
/** * page for upload face in iframe * override the js array */ public function ajax_face() { if (!$this->RequestHandler->isPost()) { $this->error(ECode::$SYS_REQUESTERROR); } $this->requestLogin(); $u = User::getInstance(); $face = Configure::read("user.face"); //init upload file if (isset($this->params['url']['name'])) { //html5 mode $tmp_name = tempnam(CACHE, "upload_"); file_put_contents($tmp_name, file_get_contents('php://input')); $file = array('tmp_name' => $tmp_name, 'name' => nforum_iconv('utf-8', $this->encoding, $this->params['url']['name']), 'size' => filesize($tmp_name), 'error' => 0); } else { if (isset($this->params['form']['file']) && is_array($this->params['form']['file'])) { //flash mode $file = $this->params['form']['file']; $file['name'] = nforum_iconv('utf-8', $this->encoding, $file['name']); } else { $this->error(ECode::$ATT_NONE); } } $errno = isset($file['error']) ? $file['error'] : UPLOAD_ERR_NO_FILE; switch ($errno) { case UPLOAD_ERR_OK: $tmpFile = $file['tmp_name']; $tmpName = $file['name']; if (!isset($tmp_name) && !is_uploaded_file($tmpFile)) { $msg = "上传错误"; break; } $ext = strrchr($tmpName, '.'); if (!in_array(strtolower($ext), $face['ext'])) { $msg = "上传文件扩展名有误"; break; } if (filesize($tmpFile) > $face['size']) { $msg = "文件大小超过上限" . $face['size'] / 1024 . "K"; break; } mt_srand(); $faceDir = $face['dir'] . DS . strtoupper(substr($u->userid, 0, 1)); $facePath = $faceDir . DS . $u->userid . "." . mt_rand(0, 10000) . $ext; $faceFullDir = WWW_ROOT . $faceDir; $faceFullPath = WWW_ROOT . $facePath; if (!is_dir($faceFullDir)) { @mkdir($faceFullDir); } if (is_file($faceFullPath)) { $msg = "我觉得您今天可以买彩票了"; break; } if (isset($tmp_name)) { if (!rename($tmp_name, $faceFullPath)) { $msg = "上传错误"; break; } } else { if (!move_uploaded_file($tmpFile, $faceFullPath)) { $msg = "上传错误"; break; } } App::import('vendor', "inc/image"); try { $img = new Image($faceFullPath); $format = $img->getFormat(); if (!in_array($format, range(1, 3))) { $msg = "上传的文件貌似不是图像文件"; break; } //gif do not thumbnail if ($format != 1) { $facePath = preg_replace("/\\.[^.]+\$/", '.jpg', $facePath); $faceFullPath = WWW_ROOT . $facePath; $img->thumbnail($faceFullPath, 120, 120); } } catch (ImageNullException $e) { $msg = "上传的文件貌似不是图像文件"; break; } $this->set("no_html_data", array("img" => $facePath, "width" => $img->getWidth(), "height" => $img->getHeight(), "ajax_st" => 1, "ajax_code" => ECode::$SYS_AJAXOK, "ajax_msg" => "文件上传成功")); return; break; case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: $msg = "文件大小超过系统上限"; break; case UPLOAD_ERR_PARTIAL: $msg = "文件传输出错!"; break; case UPLOAD_ERR_NO_FILE: $msg = "没有文件上传!"; break; default: $msg = "未知错误"; } if (isset($tmp_name)) { @unlink($tmp_name); } $this->set("no_html_data", array("ajax_st" => 0, "ajax_code" => ECode::$SYS_AJAXERROR, "ajax_msg" => $msg)); }