/** * 发送回复 */ public function sendAction() { $params = $this->_request->getParams(); // 处理附件图片 $content = !empty($params['content']) ? nl2br($params['content']) : ''; $attachments = array(); if (isset($params['image'])) { $images = $params['image']; if (!is_array($params['image'])) { $images = explode(',', $images); } foreach ($images as $fileId) { if (!$fileId) { continue; } if (false !== strpos($fileId, ',')) { $arr = explode(',', $fileId); foreach ($arr as $fid) { $attachments[] = $fid; $fid = str_replace('AID:', '', $fid); $content .= '<br /><img src="AID:' . $fid . '" _aid="' . $fid . '" />'; } continue; } $attachments[] = $fileId; $fileId = str_replace('AID:', '', $fileId); $content .= '<br /><img src="AID:' . $fileId . '" _aid="' . $fileId . '" />'; } } $attrs = array('tuduid' => isset($params['tuduid']) ? $params['tuduid'] : null, 'content' => $content, 'percent' => isset($params['percent']) ? max(0, (int) $params['percent']) : null, 'elapsedtime' => isset($params['elapsedtime']) ? (double) $params['elapsedtime'] * 3600 : null); $attrs['header'] = array('client-type' => 'iOS'); if (isset($params['postid'])) { $attrs['postid'] = $params['postid']; } if ((!empty($params['reference']) || !empty($params['reply'])) && !empty($params['tuduid'])) { $refId = !empty($params['reference']) ? $params['reference'] : $params['reply']; $isRef = !empty($params['reference']); $sql = "SELECT post_id AS postid, poster FROM td_post WHERE tudu_id = :tuduid AND is_send = 1 ORDER BY create_time ASC"; $db = Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS); $posts = $db->fetchAll($sql, array('tuduid' => $params['tuduid'])); $floor = 0; $poster = null; foreach ($posts as $item) { if ($item['postid'] == $refId) { $poster = $item['poster']; break; } $floor++; } $floorText = $floor == 1 ? '楼主' : $floor . '楼'; if ($poster) { if ($isRef) { $sql = "SELECT content FROM td_post WHERE tudu_id = :tuduid AND post_id = :postid"; $refPost = $db->fetchRow($sql, array('tuduid' => $params['tuduid'], 'postid' => $refId)); if ($refPost) { $refContent = '<div class="cite_wrap">' . '<strong>引用:</strong><span class="floor_f">' . $poster . '</span><a class="floor_f" style="margin-left:5px;" href="javascript:void(0)" _jumpfloor="' . $floor . '|' . $refId . '">' . $floorText . '</a>' . '<div>' . $refPost['content'] . '</div>' . '</div>'; $attrs['content'] = $refContent . $attrs['content']; } } else { $refContent = '<div class="cite_wrap">' . '<p>' . '<strong>回复</strong><a class="floor_f" style="margin:0 5px;" href="javascript:void(0)" _jumpfloor="FLOOR:' . $floor . '|' . $refId . '" _initfloor="' . $floor . '">' . $floorText . '</a> ' . '<span class="floor_f" style="margin-left:5px;">' . $poster . '</span>' . '</p>' . '</div>'; $attrs['content'] = $refContent . $attrs['content']; } } } $modelPost = Tudu_Model::factory('Model_Tudu_Post_Compose'); try { require_once 'Model/Tudu/Post.php'; $post = new Model_Tudu_Post($attrs); if (count($attachments)) { foreach ($attachments as $fid) { $post->addAttachment($fid, false); } } $modelPost->execute('send', array(&$post)); } catch (Model_Tudu_Exception $e) { $code = TuduX_OpenApi_ResponseCode::SYSTEM_ERROR; switch ($e->getCode()) { case Model_Tudu_Exception::TUDU_NOTEXISTS: case Model_Tudu_Exception::POST_NOTEXISTS: $code = TuduX_OpenApi_ResponseCode::RESOURCE_NOT_EXISTS; break; case Model_Tudu_Exception::TUDU_IS_DONE: $code = TuduX_OpenApi_ResponseCode::TUDU_CLOSED; break; case Model_Tudu_Exception::PERMISSION_DENIED: $code = TuduX_OpenApi_ResponseCode::ACCESS_DENIED; break; case Model_Tudu_Exception::MISSING_PARAMETER: $code = TuduX_OpenApi_ResponseCode::MISSING_PARAMETER; break; default: } throw new TuduX_OpenApi_Exception($e->getMessage(), $code); } $this->view->code = TuduX_OpenApi_ResponseCode::SUCCESS; $this->view->postid = $post->postId; }