public function copyThread(PwTopicDm $topicDm, $newTid)
 {
     $ifupload = $topicDm->getField('ifupload');
     if (!$ifupload) {
         return;
     }
     $tid = $topicDm->tid;
     $this->attachs = $this->_getService()->getAttachByTid($tid, array(0));
     if (!$this->attachs) {
         return;
     }
     foreach ($this->attachs as $v) {
         $dm = new PwThreadAttachDm();
         $dm->setFid($v['fid'])->setTid($newTid)->setPid($v['pid'])->setWidth($v['width'])->setHeight($v['height'])->setSpecial($v['special'])->setCost($v['cost'])->setCtype($v['ctype'])->addHits($v['hits'])->setName($v['name'])->setType($v['type'])->setSize($v['size'])->setPath($v['path'])->setIfthumb($v['ifthumb'])->setCreatedUser($v['created_userid'])->setCreatedTime($v['created_time'])->setApp($v['app'])->setDescrip($v['descrip']);
         $this->_getService()->addAttach($dm);
     }
 }
Ejemplo n.º 2
0
 /**
  * 批量更新附件信息
  *
  * @param array $aids
  * @param PwThreadAttachDm $dm
  * @return bool
  */
 public function batchUpdateAttach($aids, PwThreadAttachDm $dm)
 {
     if (!$aids || !is_array($aids)) {
         return false;
     }
     if (($result = $dm->beforeUpdate()) !== true) {
         return $result;
     }
     if (($result = $this->_getAttach()->batchUpdateAttach($aids, $dm)) instanceof PwError) {
         return $result;
     }
     return $this->_getDao()->batchUpdateAttach($aids, $dm->getData(), $dm->getIncreaseData());
 }
Ejemplo n.º 3
0
 /**
  * @see PwUploadAction.update
  */
 public function update($uploaddb)
 {
     $srv = Wekit::load('attach.PwThreadAttach');
     foreach ($uploaddb as $key => $value) {
         $value['name'] = WindConvert::convert($value['name'], Wind::getApp()->getResponse()->getCharset(), 'utf-8');
         $att = new PwThreadAttachDm();
         $att->setName($value['name']);
         $att->setType($value['type']);
         $att->setSize($value['size']);
         $att->setPath($value['fileuploadurl']);
         $att->setIfthumb($value['ifthumb']);
         $att->setCreatedUser($this->user->uid);
         $att->setCreatedTime(Pw::getTime());
         if ($value['thumb'] && $value['thumb'][0]) {
             $att->setWidth($value['thumb'][0][2]);
             $att->setHeight($value['thumb'][0][3]);
         }
         $att->setApp('thread');
         $aid = $srv->addAttach($att);
         $this->attachs[$aid] = array('aid' => $aid, 'name' => $value['name'], 'type' => $value['type'], 'path' => $value['fileuploadurl'], 'size' => $value['size'], 'descrip' => $value['descrip'], 'ifthumb' => $value['ifthumb']);
     }
     return true;
 }
Ejemplo n.º 4
0
 public function updateAttach()
 {
     if (!$this->_alterattach) {
         return;
     }
     foreach ($this->_alterattach as $key => $v) {
         $dm = new PwThreadAttachDm($key);
         $dm->setDescrip($v['descrip'])->setSpecial($v['special'])->setCost($v['cost'])->setCtype($v['ctype']);
         $this->_getService()->updateAttach($dm);
     }
 }
Ejemplo n.º 5
0
 /**
  * @see PwUploadAction.update
  */
 public function update($uploaddb)
 {
     $srv = Wekit::load('attach.PwThreadAttach');
     foreach ($uploaddb as $key => $value) {
         Pw::deleteAttach($this->attach['path'], $this->attach['ifthumb']);
         $att = new PwThreadAttachDm($this->aid);
         $att->setName($value['name']);
         $att->setType($value['type']);
         $att->setSize($value['size']);
         $att->setPath($value['fileuploadurl']);
         $att->setIfthumb($value['ifthumb']);
         $att->setCreatedUser($this->user->uid);
         $att->setCreatedTime(Pw::getTime());
         $att->setApp('thread');
         $srv->updateAttach($att);
         if ($this->attach['tid'] && $this->attach['pid'] == 0 && $this->attach['type'] != $value['type']) {
             Wind::import('SRV:forum.dm.PwTopicDm');
             $dm = new PwTopicDm($this->attach['tid']);
             $dm->setHasAttach($value['type'], true);
             if (!Wekit::load('attach.PwThreadAttach')->countType($this->attach['tid'], 0, $this->attach['type'])) {
                 $dm->setHasAttach($this->attach['type'], false);
             }
             Wekit::load('forum.PwThread')->updateThread($dm);
         }
         $this->attachs[$this->aid] = array('aid' => $this->aid, 'name' => $value['name'], 'type' => $value['type'], 'path' => $value['fileuploadurl'], 'size' => $value['size'], 'descrip' => $value['descrip'], 'ifthumb' => $value['ifthumb']);
         break;
     }
     return true;
 }
Ejemplo n.º 6
0
 public function downloadAction()
 {
     $aid = (int) $this->getInput('aid', 'get');
     $submit = (int) $this->getInput('submit', 'post');
     $attach = Wekit::load('attach.PwThreadAttach')->getAttach($aid);
     if (!$attach) {
         $this->showError('BBS:thread.buy.attach.error');
     }
     Wind::import('SRV:forum.bo.PwForumBo');
     $forum = new PwForumBo($attach['fid']);
     if (!$forum->isForum()) {
         $this->showError('data.error');
     }
     if ($attach['cost'] && !$this->loginUser->isExists()) {
         $this->showError('download.fail.login.not', 'bbs/attach/download');
     }
     if (!$forum->allowDownload($this->loginUser)) {
         if (!$this->loginUser->isExists()) {
             $this->showError('download.fail.login.not', 'bbs/attach/download');
         }
         $this->showError(array('BBS:forum.permissions.download.allow', array('{grouptitle}' => $this->loginUser->getGroupInfo('name'))));
     }
     if (!$forum->foruminfo['allow_download'] && !$this->loginUser->getPermission('allow_download')) {
         if (!$this->loginUser->isExists()) {
             $this->showError('download.fail.login.not', 'bbs/attach/download');
         }
         $this->showError(array('permission.download.allow', array('{grouptitle}' => $this->loginUser->getGroupInfo('name'))));
     }
     Wind::import('SRV:credit.bo.PwCreditBo');
     $creditBo = PwCreditBo::getInstance();
     // 购买积分检查
     if (($attach = $this->_checkAttachCost($attach)) instanceof PwError) {
         $this->showError($attach->getError());
     }
     // 下载积分检查
     if (($reduceDownload = $this->_checkAttachDownload('download_att', $attach, $forum)) instanceof PwError) {
         $this->showError($reduceDownload->getError());
     }
     //下载积分提示
     $lang = Wind::getComponent('i18n');
     if (1 == $this->loginUser->getPermission('allow_download') && $reduceDownload && $attach['cost']) {
         $dataShow = $lang->getMessage('BBS:thread.attachbuy.message.all', array('{buyCount}' => -$attach['cost'] . $creditBo->cType[$attach['ctype']], '{downCount}' => rtrim($reduceDownload, ',')));
     } elseif (1 == $this->loginUser->getPermission('allow_download') && $reduceDownload && !$attach['cost']) {
         $dataShow = $lang->getMessage('BBS:thread.attachbuy.message.download', array('{downCount}' => rtrim($reduceDownload, ',')));
     } elseif ($attach['cost']) {
         $dataShow = $lang->getMessage('BBS:thread.attachbuy.message.buy', array('{count}' => $this->loginUser->getCredit($attach['ctype']) . $creditBo->cType[$attach['ctype']], '{buyCount}' => -$attach['cost'] . $creditBo->cType[$attach['ctype']]));
     } else {
         $dataShow = $lang->getMessage('BBS:thread.attachbuy.message.success');
     }
     !$submit && $this->showMessage($dataShow);
     //购买积分操作
     $this->_operateBuyCredit($attach);
     // 下载积分
     if ($reduceDownload) {
         Wind::import('SRV:attach.dm.PwThreadAttachBuyDm');
         $dm = new PwThreadAttachBuyDm();
         $dm->setAid($aid)->setCreatedUserid($this->loginUser->uid)->setCreatedTime(Pw::getTime())->setCtype($attach['ctype'])->setCost($attach['cost']);
         Wekit::load('attach.PwThreadAttachDownload')->add($dm);
         $this->_operateCredit('download_att', $forum);
     }
     //更新附件点击数
     Wind::import('SRV:attach.dm.PwThreadAttachDm');
     $dm = new PwThreadAttachDm($aid);
     $dm->addHits(1);
     Wekit::load('attach.PwThreadAttach')->updateAttach($dm);
     $filename = basename($attach['path']);
     $fileext = substr(strrchr($attach['path'], '.'), 1);
     $filesize = 0;
     if (strpos(Wind::getApp()->getRequest()->getServer('HTTP_USER_AGENT'), 'MSIE') !== false && $fileext == 'torrent') {
         $attachment = 'inline';
     } else {
         $attachment = 'attachment';
     }
     $attach['name'] = trim(str_replace(' ', ' ', $attach['name']));
     if (strtoupper(Wekit::V('charset')) == 'UTF-8') {
         $attach['name'] = Pw::convert($attach['name'], "gbk", 'utf-8');
     }
     $filesize = 0;
     $fgeturl = Wind::getComponent('storage')->getDownloadUrl($attach['path']);
     if (strpos($fgeturl, 'http') !== 0) {
         if (!is_readable($fgeturl)) {
             $this->showError('BBS:thread.buy.attach.error');
         }
         $filesize = filesize($fgeturl);
     }
     $timestamp = Pw::getTime();
     $ctype = '';
     switch ($fileext) {
         case "pdf":
             $ctype = "application/pdf";
             break;
         case "rar":
         case "zip":
             $ctype = "application/zip";
             break;
         case "doc":
             $ctype = "application/msword";
             break;
         case "xls":
             $ctype = "application/vnd.ms-excel";
             break;
         case "ppt":
             $ctype = "application/vnd.ms-powerpoint";
             break;
         case "gif":
             $ctype = "image/gif";
             break;
         case "png":
             $ctype = "image/png";
             break;
         case "jpeg":
         case "jpg":
             $ctype = "image/jpeg";
             break;
         case "wav":
             $ctype = "audio/x-wav";
             break;
         case "mpeg":
         case "mpg":
         case "mpe":
             $ctype = "video/x-mpeg";
             break;
         case "mov":
             $ctype = "video/quicktime";
             break;
         case "avi":
             $ctype = "video/x-msvideo";
             break;
         case "txt":
             $ctype = "text/plain";
             break;
         default:
             $ctype = "application/octet-stream";
     }
     ob_end_clean();
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $timestamp + 86400) . ' GMT');
     header('Expires: ' . gmdate('D, d M Y H:i:s', $timestamp + 86400) . ' GMT');
     header('Cache-control: max-age=86400');
     header('Content-Encoding: none');
     header("Content-Disposition: {$attachment}; filename=\"{$attach['name']}\"");
     header("Content-type: {$ctype}");
     header("Content-Transfer-Encoding: binary");
     $filesize && header("Content-Length: {$filesize}");
     $i = 1;
     while (!@readfile($fgeturl)) {
         if (++$i > 3) {
             break;
         }
     }
     exit;
 }
Ejemplo n.º 7
0
 /**
  * @see PwUploadAction.update
  */
 public function update($uploaddb)
 {
     $this->transfer();
     $srv = $this->_getService();
     foreach ($uploaddb as $key => $value) {
         $att = new PwThreadAttachDm();
         $att->setName($value['name']);
         $att->setType($value['type']);
         $att->setSize($value['size']);
         $att->setPath($value['fileuploadurl']);
         $att->setIfthumb($value['ifthumb']);
         $att->setCreatedUser($this->user->uid);
         $att->setCreatedTime(Pw::getTime());
         $att->setApp('thread');
         $aid = $srv->addAttach($att);
         $this->attachs[$aid] = array('aid' => $aid, 'name' => $value['name'], 'type' => $value['type'], 'path' => $value['fileuploadurl'], 'size' => $value['size'], 'descrip' => $value['descrip'], 'ifthumb' => $value['ifthumb']);
     }
     return true;
 }