| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- /**
- * The zen file of file module of ZenTaoPMS.
- *
- * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
- * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
- * @author Yidong Wang<yidong@easycorp.ltd>
- * @package file
- * @link https://www.zentao.net
- */
- class fileZen extends file
- {
- /**
- * 获取下载方式,是下载文件还是直接在页面打开查看。
- * Get download mode
- *
- * @param object $file
- * @param string $mouse
- * @access protected
- * @return string down|open
- */
- protected function getDownloadMode($file, $mouse)
- {
- $mode = 'down';
- $fileTypes = 'txt|jpg|jpeg|gif|png|bmp|xml|html|mp4';
- if(stripos($fileTypes, $file->extension) !== false && $mouse == 'left') $mode = 'open';
- return $mode;
- }
- /**
- * 构建下载列表表格。
- * Build download table.
- *
- * @param array $fields
- * @param array $rows
- * @param string $kind
- * @param array $rowspans
- * @param array $colspans
- * @access protected
- * @return string
- */
- protected function buildDownloadTable($fields, $rows, $kind, $rowspans = array(), $colspans = array())
- {
- $rows = array_values($rows);
- $host = common::getSysURL();
- $fileModel = $this->file;
- $output = "<table><tr>";
- $output .= implode("\n", array_map(function($fieldLabel){return "<th><nobr>$fieldLabel</nobr></th>";}, $fields));
- $output .= "</tr>";
- foreach($rows as $i => $row)
- {
- if(in_array($kind, array('story', 'bug', 'testcase'))) $row->title = html::a($host . $this->createLink($kind, 'view', "{$kind}ID=$row->id"), $row->title, '_blank');
- if($kind == 'task') $row->name = html::a($host . $this->createLink('task', 'view', "taskID=$row->id"), $row->name, '_blank');
- $output .= "<tr valign='top'>\n";
- $col = 0;
- $endColspan = 0;
- foreach($fields as $fieldName => $fieldLabel)
- {
- $col ++;
- if(!empty($endColspan) && $col < $endColspan) continue;
- if(isset($endRowspan[$fieldName]) && $i < $endRowspan[$fieldName]) continue;
- $fieldValue = zget($row, $fieldName, '');
- $rowspan = '';
- if(isset($rowspans[$i]) && isset($rowspans[$i]['rows'][$fieldName]))
- {
- $rowspan = "rowspan='{$rowspans[$i]['rows'][$fieldName]}'";
- $endRowspan[$fieldName] = $i + $rowspans[$i]['rows'][$fieldName];
- }
- $colspan = '';
- if(isset($colspans[$i]) && isset($colspans[$i]['cols'][$fieldName]))
- {
- $colspan = "colspan='{$colspans[$i]['cols'][$fieldName]}'";
- $endColspan = $col + $colspans[$i]['cols'][$fieldName];
- }
- if($fieldValue && is_string($fieldValue))
- {
- $fieldValue = preg_replace_callback('/ src="{([0-9]+)(\.(\w+))?}" /', function($matches) use($host, $fileModel)
- {
- $file = $fileModel->getById((int)$matches[1]);
- return $file ? ' src="' . $host . $file->webPath . '" ' : $matches[0];
- }, $fieldValue);
- }
- $output .= "<td $rowspan $colspan><nobr>$fieldValue</nobr></td>\n";
- }
- $output .= "</tr>\n";
- }
- $output .= "</table>";
- return $output;
- }
- /**
- * 删除真实文件。
- * Unlink real file.
- *
- * @param object $file
- * @access protected
- * @return void
- */
- protected function unlinkRealFile($file)
- {
- $fileRecord = $this->dao->select('id')->from(TABLE_FILE)->where('pathname')->eq($file->pathname)->fetch();
- if(empty($fileRecord)) $this->file->unlinkFile($file);
- }
- /**
- * 更新 fileName 字段。
- * Update fileName field.
- *
- * @param int $fileID
- * @access protected
- * @return array
- */
- protected function updateFileName($fileID)
- {
- $file = $this->file->getByID($fileID);
- if(!$file) return array('result' => 'fail', 'code' => 404, 'message' => $this->lang->file->fileNotFound);
- $data = fixer::input('post')->get();
- if(validater::checkLength($data->fileName, 80, 1) == false) return array('result' => 'fail', 'message' => sprintf($this->lang->error->length[1], $this->lang->file->title, 80, 1));
- $fileName = $data->fileName;
- if(isset($data->extension))
- {
- $extension = $data->extension;
- }
- else
- {
- $extension = strpos($fileName, '.') !== false ? end(explode('.', $fileName)) : $file->extension;
- }
- $this->dao->update(TABLE_FILE)
- ->set('title')->eq($fileName)
- ->beginIF($extension)->set('extension')->eq($extension)->fi()
- ->where('id')->eq($fileID)
- ->exec();
- if($file->objectType) $actionID = $this->loadModel('action')->create($file->objectType, $file->objectID, 'editfile', '', $fileName);
- $changes[] = array('field' => 'fileName', 'old' => $file->title, 'new' => $fileName, 'diff' => '');
- $this->action->logHistory($actionID, $changes);
- /* Update test case version for test case synchronization. */
- if($file->objectType == 'testcase' and $file->title != $fileName) $this->file->updateTestcaseVersion($file);
- return array('result' => 'success');
- }
- }
|