Esempio n. 1
0
 /**
  * 发送回复
  */
 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;
 }
Esempio n. 2
0
 /**
  *
  * @param Model_Tudu_Post $post
  */
 public function save(Model_Tudu_Post &$post)
 {
     $time = time();
     /* @var $daoPost Dao_Td_Tudu_Post */
     $daoPost = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Post', Tudu_Dao_Manager::DB_TS);
     $params = array('content' => $post->content);
     if (null !== $post->percent) {
         $params['percent'] = $post->percent;
     }
     if (null !== $post->elapsedTime) {
         $params['elapsedtime'] = $post->elapsedTime;
     }
     if (null === $this->_fromPost) {
         $post->postId = Dao_Td_Tudu_Post::getPostId($this->_tudu->tuduId);
         $params['postid'] = $post->postId;
         $params['orgid'] = $this->_tudu->orgId;
         $params['boardid'] = $this->_tudu->boardId;
         $params['tuduid'] = $this->_tudu->tuduId;
         $params['uniqueid'] = $this->_user->uniqueId;
         $params['email'] = $this->_user->userName;
         $params['poster'] = $this->_user->trueName;
         $params['posterinfo'] = $this->_user->position;
         if (!$daoPost->createPost($params)) {
             require 'Model/Tudu/Exception.php';
             throw new Model_Tudu_Exception('Save post failed', Model_Tudu_Exception::PERMISSION_DENIED);
         }
     } else {
         // 增加最后编辑信息
         if ($this->_fromPost->isSend) {
             $params['lastmodify'] = implode(chr(9), array($this->_user->uniqueId, $time, $this->_user->trueName));
         } else {
             $params['createtime'] = $time;
         }
         if (!$daoPost->updatePost($this->_tudu->tuduId, $this->_fromPost->postId, $params)) {
             require 'Model/Tudu/Exception.php';
             throw new Model_Tudu_Exception('Save post failed', Model_Tudu_Exception::PERMISSION_DENIED);
         }
     }
     $attachments = $post->getAttachments();
     if (count($attachments)) {
         /* @var $daoFile Td_Attachment_File */
         $daoFile = Tudu_Dao_Manager::getDao('Dao_Td_Attachment_File', Tudu_Dao_Manager::DB_TS);
         /* @var $daoNdFile Td_Netdisk_File */
         $daoNdFile = Tudu_Dao_Manager::getDao('Dao_Td_Netdisk_File', Tudu_Dao_Manager::DB_TS);
         foreach ($attachments as $attach) {
             if ($attach['isnetdisk']) {
                 $fileId = $attach['fileid'];
                 if (null !== $daoFile->getFile(array('fileid' => $fileId))) {
                     $ret['attachment'][] = $fileId;
                     continue;
                 }
                 $file = $daoNdFile->getFile(array('uniqueid' => $this->_user->uniqueId, 'fileid' => $fileId));
                 if (null === $file) {
                     continue;
                 }
                 $fileId = $file->fromFileId ? $file->fromFileId : $file->attachFileId;
                 $ret = $daoFile->createFile(array('uniqueid' => $this->_user->uniqueId, 'fileid' => $fileId, 'orgid' => $this->_user->orgId, 'filename' => $file->fileName, 'path' => $file->path, 'type' => $file->type, 'size' => $file->size, 'createtime' => $time));
                 if (!$ret) {
                     continue;
                 }
                 $attach['fileid'] = $fileId;
             }
             $daoFile->addPost($this->_tudu->tuduId, $post->postId, $attach['fileid'], $attach['isattach']);
         }
     }
     $updates = array();
     if (null !== $this->_fromPost) {
         $arrFromPost = $this->_fromPost->toArray();
         foreach ($params as $key => $val) {
             if (in_array($key, array('file', 'attachment'))) {
                 continue;
             }
             if ($val != $arrFromPost[$key]) {
                 $updates[$key] = $val;
             }
         }
     } else {
         $updates = $params;
     }
     /* @var $daoLog Dao_Td_Log_Log */
     $daoLog = Tudu_Dao_Manager::getDao('Dao_Td_Log_Log', Tudu_Dao_Manager::DB_TS);
     $daoLog->createLog(array('orgid' => $this->_user->orgId, 'uniqueid' => $this->_user->uniqueId, 'operator' => $this->_user->userName . ' ' . $this->_user->trueName, 'logtime' => $time, 'targettype' => Dao_Td_Log_Log::TYPE_POST, 'targetid' => $post->postId, 'action' => $this->_fromPost ? Dao_Td_Log_Log::ACTION_CREATE : Dao_Td_Log_Log::ACTION_UPDATE, 'detail' => serialize($updates), 'privacy' => 0));
 }