Example #1
0
 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);
 }
Example #2
0
 /**
  * post file via deliver
  * @param String $board
  * @param String $title
  * @param String $content
  * @return {v:}
  */
 public function a_autopost()
 {
     @($board = urldecode(trim($this->params['url']['board'])));
     @($title = urldecode(trim($this->params['url']['title'])));
     @($content = urldecode(trim($this->params['url']['content'])));
     if (isset($this->params['form']['board'])) {
         $board = trim($this->params['form']['board']);
     }
     if (isset($this->params['form']['title'])) {
         $title = trim($this->params['form']['title']);
     }
     if (isset($this->params['form']['content'])) {
         $content = trim($this->params['form']['content']);
     }
     if ($board == "" || $title == "") {
         $this->_stop();
     }
     App::import("vendor", "model/article");
     $ret = Article::autoPost($board, $title, $content);
     echo BYRJSON::encode(array("v" => $ret));
 }