diff --git a/module/action/model.php b/module/action/model.php index c55dd5d0b1..cfa77affe7 100755 --- a/module/action/model.php +++ b/module/action/model.php @@ -47,7 +47,7 @@ class actionModel extends model $action->extra = $extra; /* Process action. */ - $action = $this->loadModel('file')->processEditor($action, 'comment', $this->post->uid); + $action = $this->loadModel('file')->processImgURL($action, 'comment', $this->post->uid); /* Get product and project for this object. */ $productAndProject = $this->getProductAndProject($action->objectType, $objectID); @@ -893,7 +893,7 @@ class actionModel extends model $action->comment = trim(strip_tags($this->post->lastComment, $this->config->allowedTags)); /* Process action. */ - $action = $this->loadModel('file')->processEditor($action, 'comment', $this->post->uid); + $action = $this->loadModel('file')->processImgURL($action, 'comment', $this->post->uid); $this->dao->update(TABLE_ACTION) ->set('date')->eq(helper::now()) diff --git a/module/block/model.php b/module/block/model.php index c82192e417..80911538a3 100644 --- a/module/block/model.php +++ b/module/block/model.php @@ -41,7 +41,7 @@ class blockModel extends model if($type == 'html') { $uid = $this->post->uid; - $data = $this->loadModel('file')->processEditor($data, 'html', $uid); + $data = $this->loadModel('file')->processImgURL($data, 'html', $uid); $data->params['html'] = $data->html; unset($data->html); unset($_SESSION['album'][$uid]); diff --git a/module/bug/control.php b/module/bug/control.php index 476a152ba4..3f79ae9a80 100644 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -1444,7 +1444,7 @@ class bug extends control { foreach($relatedFiles[$bug->id] as $file) { - $fileURL = common::getSysURL() . $this->file->webPath . $file->pathname; + $fileURL = common::getSysURL() . $this->file->webPath . $this->file->getRealPathName($file->pathname); $bug->files .= html::a($fileURL, $file->title, '_blank') . '
'; } } diff --git a/module/bug/model.php b/module/bug/model.php index 3bb38730b9..ee362bf857 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -78,7 +78,7 @@ class bugModel extends model $result = $this->loadModel('common')->removeDuplicate('bug', $bug, "product={$bug->product}"); if($result['stop']) return array('status' => 'exists', 'id' => $result['duplicate']); - $bug = $this->loadModel('file')->processEditor($bug, $this->config->bug->editor->create['id'], $this->post->uid); + $bug = $this->loadModel('file')->processImgURL($bug, $this->config->bug->editor->create['id'], $this->post->uid); $this->dao->insert(TABLE_BUG)->data($bug)->autoCheck()->batchCheck($this->config->bug->create->requiredFields, 'notempty')->exec(); if(!dao::isError()) { @@ -172,7 +172,7 @@ class bugModel extends model $realPath = $file['realpath']; unset($file['realpath']); - if(rename($realPath, $this->file->savePath . $file['pathname'])) + if(rename($realPath, $this->file->savePath . $this->file->getSaveName($file['pathname']))) { if(in_array($file['extension'], $this->config->file->imageExtensions)) { @@ -181,7 +181,7 @@ class bugModel extends model $this->dao->insert(TABLE_FILE)->data($file)->exec(); $fileID = $this->dao->lastInsertID; - $bug->steps .= ''; + $bug->steps .= ''; unset($file); } } @@ -361,7 +361,7 @@ class bugModel extends model ->where('t1.id')->eq((int)$bugID)->fetch(); if(!$bug) return false; - $bug = $this->loadModel('file')->revertRealSRC($bug, 'steps'); + $bug = $this->loadModel('file')->replaceImgURL($bug, 'steps'); if($setImgSize) $bug->steps = $this->file->setImgSize($bug->steps); foreach($bug as $key => $value) if(strpos($key, 'Date') !== false and !(int)substr($value, 0, 4)) $bug->$key = ''; @@ -528,7 +528,7 @@ class bugModel extends model ->remove('comment,files,labels,uid') ->get(); - $bug = $this->loadModel('file')->processEditor($bug, $this->config->bug->editor->edit['id'], $this->post->uid); + $bug = $this->loadModel('file')->processImgURL($bug, $this->config->bug->editor->edit['id'], $this->post->uid); $this->dao->update(TABLE_BUG)->data($bug) ->autoCheck() ->batchCheck($this->config->bug->edit->requiredFields, 'notempty') diff --git a/module/build/model.php b/module/build/model.php index 89e2175a88..c5c3afee43 100644 --- a/module/build/model.php +++ b/module/build/model.php @@ -31,7 +31,7 @@ class buildModel extends model ->fetch(); if(!$build) return false; - $build = $this->loadModel('file')->revertRealSRC($build, 'desc'); + $build = $this->loadModel('file')->replaceImgURL($build, 'desc'); $build->files = $this->file->getByObject('build', $buildID); if($setImgSize) $build->desc = $this->file->setImgSize($build->desc); return $build; @@ -201,7 +201,7 @@ class buildModel extends model ->remove('resolvedBy,allchecker,files,labels,uid') ->get(); - $build = $this->loadModel('file')->processEditor($build, $this->config->build->editor->create['id'], $this->post->uid); + $build = $this->loadModel('file')->processImgURL($build, $this->config->build->editor->create['id'], $this->post->uid); $this->dao->insert(TABLE_BUILD)->data($build) ->autoCheck() ->batchCheck($this->config->build->create->requiredFields, 'notempty') @@ -231,7 +231,7 @@ class buildModel extends model ->get(); if(!isset($build->branch)) $build->branch = $oldBuild->branch; - $build = $this->loadModel('file')->processEditor($build, $this->config->build->editor->edit['id'], $this->post->uid); + $build = $this->loadModel('file')->processImgURL($build, $this->config->build->editor->edit['id'], $this->post->uid); $this->dao->update(TABLE_BUILD)->data($build) ->autoCheck() ->batchCheck($this->config->build->edit->requiredFields, 'notempty') diff --git a/module/doc/model.php b/module/doc/model.php index 8c6581c4cb..7f0fa648aa 100644 --- a/module/doc/model.php +++ b/module/doc/model.php @@ -331,8 +331,9 @@ class docModel extends model $docFiles = array(); foreach($files as $file) { - $file->webPath = $this->file->webPath . $file->pathname; - $file->realPath = $this->file->savePath . $file->pathname; + $pathName = $this->file->getRealPathName($file->pathname); + $file->webPath = $this->file->webPath . $pathName; + $file->realPath = $this->file->savePath . $pathName; if(strpos(",{$docContent->files},", ",{$file->id},") !== false) $docFiles[$file->id] = $file; } @@ -352,7 +353,7 @@ class docModel extends model $doc->content = isset($docContent->content) ? $docContent->content : ''; $doc->contentType = isset($docContent->type) ? $docContent->type : ''; - $doc = $this->loadModel('file')->revertRealSRC($doc, 'content'); + $doc = $this->loadModel('file')->replaceImgURL($doc, 'content'); if($setImgSize) $doc->content = $this->file->setImgSize($doc->content); $doc->files = $docFiles; @@ -393,7 +394,7 @@ class docModel extends model if($result['stop']) return array('status' => 'exists', 'id' => $result['duplicate']); $lib = $this->getLibByID($doc->lib); - $doc = $this->loadModel('file')->processEditor($doc, $this->config->doc->editor->create['id'], $this->post->uid); + $doc = $this->loadModel('file')->processImgURL($doc, $this->config->doc->editor->create['id'], $this->post->uid); $doc->product = $lib->product; $doc->project = $lib->project; if($doc->type == 'url') @@ -454,7 +455,7 @@ class docModel extends model if($oldDoc->contentType == 'markdown') $doc->content = str_replace('>', '>', $doc->content); $lib = $this->getLibByID($doc->lib); - $doc = $this->loadModel('file')->processEditor($doc, $this->config->doc->editor->edit['id'], $this->post->uid); + $doc = $this->loadModel('file')->processImgURL($doc, $this->config->doc->editor->edit['id'], $this->post->uid); $doc->product = $lib->product; $doc->project = $lib->project; if($doc->type == 'url') $doc->content = $doc->url; @@ -952,8 +953,9 @@ class docModel extends model foreach($files as $fileID => $file) { - $file->realPath = $this->file->savePath . $file->pathname; - $file->webPath = $this->file->webPath . $file->pathname; + $pathName = $this->file->getRealPathName($file->pathname); + $file->realPath = $this->file->savePath . $pathName; + $file->webPath = $this->file->webPath . $pathName; } return $files; diff --git a/module/file/model.php b/module/file/model.php index ce11d2e478..d8a6265862 100644 --- a/module/file/model.php +++ b/module/file/model.php @@ -51,8 +51,9 @@ class fileModel extends model ->fetchAll('id'); foreach($files as $file) { - $file->webPath = $this->webPath . $file->pathname; - $file->realPath = $this->app->getAppRoot() . "www/data/upload/{$this->app->company->id}/" . $file->pathname; + $realPathName = $this->getRealPathName($file->pathname); + $file->realPath = $this->savePath . $realPathName; + $file->webPath = $this->webPath . $realPathName; } return $files; } @@ -67,8 +68,10 @@ class fileModel extends model public function getById($fileID) { $file = $this->dao->findById($fileID)->from(TABLE_FILE)->fetch(); - $file->webPath = $this->webPath . $file->pathname; - $file->realPath = $this->savePath . $file->pathname; + + $realPathName = $this->getRealPathName($file->pathname); + $file->realPath = $this->savePath . $realPathName; + $file->webPath = $this->webPath . $realPathName; return $file; } @@ -92,7 +95,7 @@ class fileModel extends model foreach($files as $id => $file) { if($file['size'] == 0) continue; - if(!move_uploaded_file($file['tmpname'], $this->savePath . $file['pathname'])) return false; + if(!move_uploaded_file($file['tmpname'], $this->savePath . $this->getSaveName($file['pathname']))) return false; $file = $this->compressImage($file); @@ -233,6 +236,7 @@ class fileModel extends model if(!is_dir($tmpFileSavePath)) mkdir($tmpFileSavePath); $fileName = basename($file['pathname']); + $fileName = strpos($fileName, '.') === false ? $fileName : substr($fileName, 0, strpos($fileName, '.')); $file['realpath'] = $tmpFileSavePath . $fileName; if($file['chunks'] > 1) @@ -297,6 +301,34 @@ class fileModel extends model return $extension; } + /** + * Get save name. + * + * @param string $pathName + * @access public + * @return string + */ + public function getSaveName($pathName) + { + $saveName = strpos($pathName, '.') === false ? $pathName : substr($pathName, 0, strpos($pathName, '.')); + return $saveName; + } + + /** + * Get real path name. + * + * @param string $pathName + * @access public + * @return string + */ + public function getRealPathName($pathName) + { + $realPath = $this->savePath . $pathName; + if(file_exists($realPath)) return $pathName; + + return $this->getSaveName($pathName); + } + /** * Get export tpl. * @@ -393,16 +425,7 @@ class fileModel extends model $readLinkReg = str_replace(array('%fileID%', '/', '.', '?'), array('[0-9]+', '\/', '\.', '\?'), helper::createLink('file', 'read', 'fileID=(%fileID%)', '\w+')); $content = preg_replace('/ src="(' . $readLinkReg . ')" /', ' onload="setImageSize(this,' . $maxSize . ')" src="$1" ', $content); - preg_match_all('/ src="{([0-9]+)}" /', $content, $matchs); - if(!empty($matchs[1])) - { - $files = $this->dao->select('id,extension')->from(TABLE_FILE)->where('id')->in($matchs[1])->fetchPairs('id', 'extension'); - foreach($matchs[0] as $i => $match) - { - $fileID = $matchs[1][$i]; - $content = str_replace($match, ' onload="setImageSize(this,' . $maxSize . ')" src="' . helper::createLink('file', 'read', "fileID=$fileID", $files[$fileID]) . '" ', $content); - } - } + $content = preg_replace('/ src="{([0-9]+)(\.(\w+))?}" /', ' onload="setImageSize(this,' . $maxSize . ')" src="' . helper::createLink('file', 'read', "fileID=$1", "$3") . '" ', $content); return str_replace(' src="data/upload', ' onload="setImageSize(this,' . $maxSize . ')" src="data/upload', $content); } @@ -419,7 +442,7 @@ class fileModel extends model $file = $files[0]; $filePath = $this->dao->select('pathname')->from(TABLE_FILE)->where('id')->eq($fileID)->fetch(); $pathName = $filePath->pathname; - $realPathName= $this->savePath . $pathName; + $realPathName = $this->savePath . $this->getRealPathName($pathName); if(!is_dir(dirname($realPathName)))mkdir(dirname($realPathName)); move_uploaded_file($file['tmpname'], $realPathName); @@ -467,7 +490,7 @@ class fileModel extends model $file['addedDate'] = helper::today(); $file['title'] = basename($file['pathname']); - file_put_contents($this->savePath . $file['pathname'], $imageData); + file_put_contents($this->savePath . $this->getSaveName($file['pathname']), $imageData); $this->dao->insert(TABLE_FILE)->data($file)->exec(); $fileID = $this->dao->lastInsertID(); if($uid) $_SESSION['album'][$uid][] = $fileID; @@ -601,17 +624,20 @@ class fileModel extends model * @access public * @return object */ - public function processEditor($data, $editorList, $uid = '') + public function processImgURL($data, $editorList, $uid = '') { if(is_string($editorList)) $editorList = explode(',', str_replace(' ', '', $editorList)); - $readLinkReg = basename(helper::createLink('file', 'read', 'fileID=(%fileID%)', '\w+')); + $readLinkReg = basename(helper::createLink('file', 'read', 'fileID=(%fileID%)', '(\w+)')); $readLinkReg = str_replace(array('%fileID%', '?'), array('[0-9]+', '\?'), $readLinkReg); foreach($editorList as $editorID) { if(empty($editorID) or empty($data->$editorID)) continue; + + $imgURL = $this->config->requestType == 'GET' ? '{$2.$1}' : '{$1.$2}'; + $data->$editorID = $this->pasteImage($data->$editorID, $uid); - $data->$editorID = preg_replace("/ src=\"$readLinkReg\" /", ' src="{$1}" ', $data->$editorID); - $data->$editorID = preg_replace("/ src=\"" . htmlspecialchars($readLinkReg) . "\" /", ' src="{$1}" ', $data->$editorID); + $data->$editorID = preg_replace("/ src=\"$readLinkReg\" /", ' src="' . $imgURL . '" ', $data->$editorID); + $data->$editorID = preg_replace("/ src=\"" . htmlspecialchars($readLinkReg) . "\" /", ' src="' . $imgURL . '" ', $data->$editorID); } return $data; } @@ -628,8 +654,8 @@ class fileModel extends model if(!extension_loaded('gd') or !function_exists('imagecreatefromjpeg')) return $file; $pathName = $file['pathname']; - $fileName = $this->savePath . $pathName; - $suffix = strrchr($fileName, '.'); + $fileName = $this->savePath . $this->getSaveName($pathName); + $suffix = $file['extension']; $lowerSuffix = strtolower($suffix); if(!in_array($lowerSuffix, $this->config->file->image2Compress)) return $file; @@ -639,12 +665,11 @@ class fileModel extends model $compressedName = str_replace($suffix, $newSuffix, $pathName); $res = $lowerSuffix == '.bmp' ? $this->imagecreatefrombmp($fileName) : imagecreatefromjpeg($fileName); - imagejpeg($res, $this->savePath . $compressedName, $quality); - if($fileName != $this->savePath . $compressedName) unlink($fileName); + imagejpeg($res, $fileName, $quality); - $file['pathname'] = $compressedName; - $file['extension'] = ltrim($newSuffix, '.'); - $file['size'] = filesize($this->savePath . $compressedName); + $file['pathname'] = $compressedName; + $file['extension'] = ltrim($newSuffix, '.'); + $file['size'] = filesize($fileName); return $file; } @@ -744,22 +769,13 @@ class fileModel extends model * @access public * @return object */ - public function revertRealSRC($data, $fields) + public function replaceImgURL($data, $fields) { if(is_string($fields)) $fields = explode(',', str_replace(' ', '', $fields)); foreach($fields as $field) { if(empty($field) or empty($data->$field)) continue; - preg_match_all('/ src="{([0-9]+)}" /', $data->$field, $matchs); - if(!empty($matchs[1])) - { - $files = $this->dao->select('id,extension')->from(TABLE_FILE)->where('id')->in($matchs[1])->fetchPairs('id', 'extension'); - foreach($matchs[0] as $i => $match) - { - $fileID = $matchs[1][$i]; - $data->$field = str_replace($match, ' src="' . helper::createLink('file', 'read', "fileID=$fileID", $files[$fileID]) . '" ', $data->$field); - } - } + $data->$field = preg_replace('/ src="{([0-9]+)(\.(\w+))?}" /', ' src="' . helper::createLink('file', 'read', "fileID=$1", "$3") . '" ', $data->$field); } return $data; diff --git a/module/mail/model.php b/module/mail/model.php index fcc002361d..1cb6b912fa 100644 --- a/module/mail/model.php +++ b/module/mail/model.php @@ -305,10 +305,10 @@ class mailModel extends model /* Replace full webPath image for mail. */ $sysURL = zget($this->config->mail, 'domain', common::getSysURL()); - $readLinkReg = htmlspecialchars(str_replace(array('%fileID%', '/', '?'), array('[0-9]+', '\/', '\?'), helper::createLink('file', 'read', 'fileID=(%fileID%)'))); + $readLinkReg = str_replace(array('%fileID%', '/', '.', '?'), array('[0-9]+', '\/', '\.', '\?'), helper::createLink('file', 'read', 'fileID=(%fileID%)', '\w+')); $body = preg_replace('/ src="(' . $readLinkReg . ')" /', ' src="' . $sysURL . '$1" ', $body); - $body = preg_replace('/ src="{([0-9]+)}" /', ' src="' . $sysURL . helper::createLink('file', 'read', "fileID=$1") . '" ', $body); + $body = preg_replace('/ src="{([0-9]+)(\.(\w+))?}" /', ' src="' . $sysURL . helper::createLink('file', 'read', "fileID=$1", "$3") . '" ', $body); $body = preg_replace('/config->webRoot . 'data/upload', $body); try diff --git a/module/product/model.php b/module/product/model.php index 7099e4d59c..49a62bc57b 100644 --- a/module/product/model.php +++ b/module/product/model.php @@ -181,7 +181,7 @@ class productModel extends model { if(defined('TUTORIAL')) return $this->loadModel('tutorial')->getProduct(); $product = $this->dao->findById($productID)->from(TABLE_PRODUCT)->fetch(); - return $this->loadModel('file')->revertRealSRC($product, 'desc'); + return $this->loadModel('file')->replaceImgURL($product, 'desc'); } /** @@ -288,7 +288,7 @@ class productModel extends model ->stripTags($this->config->product->editor->create['id'], $this->config->allowedTags) ->remove('uid') ->get(); - $product = $this->loadModel('file')->processEditor($product, $this->config->product->editor->create['id'], $this->post->uid); + $product = $this->loadModel('file')->processImgURL($product, $this->config->product->editor->create['id'], $this->post->uid); $this->dao->insert(TABLE_PRODUCT)->data($product)->autoCheck() ->batchCheck('name,code', 'notempty') ->check('name', 'unique', "deleted = '0'") @@ -328,7 +328,7 @@ class productModel extends model ->stripTags($this->config->product->editor->edit['id'], $this->config->allowedTags) ->remove('uid') ->get(); - $product = $this->loadModel('file')->processEditor($product, $this->config->product->editor->edit['id'], $this->post->uid); + $product = $this->loadModel('file')->processImgURL($product, $this->config->product->editor->edit['id'], $this->post->uid); $this->dao->update(TABLE_PRODUCT)->data($product)->autoCheck() ->batchCheck('name,code', 'notempty') ->check('name', 'unique', "id != $productID and deleted = '0'") diff --git a/module/productplan/model.php b/module/productplan/model.php index b10232e07c..b658137879 100644 --- a/module/productplan/model.php +++ b/module/productplan/model.php @@ -24,7 +24,7 @@ class productplanModel extends model public function getByID($planID, $setImgSize = false) { $plan = $this->dao->findByID((int)$planID)->from(TABLE_PRODUCTPLAN)->fetch(); - $plan = $this->loadModel('file')->revertRealSRC($plan, 'desc'); + $plan = $this->loadModel('file')->replaceImgURL($plan, 'desc'); if($setImgSize) $plan->desc = $this->file->setImgSize($plan->desc); return $plan; } @@ -138,7 +138,7 @@ class productplanModel extends model public function create() { $plan = fixer::input('post')->stripTags($this->config->productplan->editor->create['id'], $this->config->allowedTags)->remove('delta,uid')->get(); - $plan = $this->loadModel('file')->processEditor($plan, $this->config->plan->editor->create['id'], $this->post->uid); + $plan = $this->loadModel('file')->processImgURL($plan, $this->config->plan->editor->create['id'], $this->post->uid); $this->dao->insert(TABLE_PRODUCTPLAN) ->data($plan) ->autoCheck() @@ -164,7 +164,7 @@ class productplanModel extends model { $oldPlan = $this->dao->findByID((int)$planID)->from(TABLE_PRODUCTPLAN)->fetch(); $plan = fixer::input('post')->stripTags($this->config->productplan->editor->edit['id'], $this->config->allowedTags)->remove('delta,uid')->get(); - $plan = $this->loadModel('file')->processEditor($plan, $this->config->plan->editor->edit['id'], $this->post->uid); + $plan = $this->loadModel('file')->processImgURL($plan, $this->config->plan->editor->edit['id'], $this->post->uid); $this->dao->update(TABLE_PRODUCTPLAN) ->data($plan) ->autoCheck() diff --git a/module/project/model.php b/module/project/model.php index 41c01b8391..a6dd951688 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -234,7 +234,7 @@ class projectModel extends model ->stripTags($this->config->project->editor->create['id'], $this->config->allowedTags) ->remove('products, workDays, delta, branch,uid') ->get(); - $project = $this->loadModel('file')->processEditor($project, $this->config->project->editor->create['id'], $this->post->uid); + $project = $this->loadModel('file')->processImgURL($project, $this->config->project->editor->create['id'], $this->post->uid); $this->dao->insert(TABLE_PROJECT)->data($project) ->autoCheck($skipFields = 'begin,end') ->batchcheck($this->config->project->create->requiredFields, 'notempty') @@ -318,7 +318,7 @@ class projectModel extends model ->stripTags($this->config->project->editor->edit['id'], $this->config->allowedTags) ->remove('products,branch,uid') ->get(); - $project = $this->loadModel('file')->processEditor($project, $this->config->project->editor->edit['id'], $this->post->uid); + $project = $this->loadModel('file')->processImgURL($project, $this->config->project->editor->edit['id'], $this->post->uid); $this->dao->update(TABLE_PROJECT)->data($project) ->autoCheck($skipFields = 'begin,end') ->batchcheck($this->config->project->edit->requiredFields, 'notempty') @@ -890,7 +890,7 @@ class projectModel extends model $project->totalConsumed = round($total->totalConsumed, 1); $project->totalLeft = round($total->totalLeft, 1); - $project = $this->loadModel('file')->revertRealSRC($project, 'desc'); + $project = $this->loadModel('file')->replaceImgURL($project, 'desc'); if($setImgSize) $project->desc = $this->file->setImgSize($project->desc); return $project; diff --git a/module/release/model.php b/module/release/model.php index e8a95d867c..d7fdf1153d 100644 --- a/module/release/model.php +++ b/module/release/model.php @@ -33,7 +33,7 @@ class releaseModel extends model if(!$release) return false; $this->loadModel('file'); - $release = $this->file->revertRealSRC($release, 'desc'); + $release = $this->file->replaceImgURL($release, 'desc'); $release->files = $this->file->getByObject('release', $releaseID); if(empty($release->files))$release->files = $this->file->getByObject('build', $release->buildID); if($setImgSize) $release->desc = $this->file->setImgSize($release->desc); @@ -113,7 +113,7 @@ class releaseModel extends model ->stripTags($this->config->release->editor->create['id'], $this->config->allowedTags) ->remove('build,files,labels,uid') ->get(); - $build = $this->loadModel('file')->processEditor($build, $this->config->release->editor->create['id']); + $build = $this->loadModel('file')->processImgURL($build, $this->config->release->editor->create['id']); $this->dao->insert(TABLE_BUILD)->data($build) ->autoCheck() ->check('name', 'unique', "product = {$build->product} AND branch = $branch AND deleted = '0'") @@ -133,7 +133,7 @@ class releaseModel extends model ->remove('allchecker,files,labels,uid') ->get(); - $release = $this->loadModel('file')->processEditor($release, $this->config->release->editor->create['id'], $this->post->uid); + $release = $this->loadModel('file')->processImgURL($release, $this->config->release->editor->create['id'], $this->post->uid); $this->dao->insert(TABLE_RELEASE)->data($release) ->autoCheck() ->batchCheck($this->config->release->create->requiredFields, 'notempty') @@ -167,7 +167,7 @@ class releaseModel extends model ->add('branch', (int)$branch) ->remove('files,labels,allchecker,uid') ->get(); - $release = $this->loadModel('file')->processEditor($release, $this->config->release->editor->edit['id'], $this->post->uid); + $release = $this->loadModel('file')->processImgURL($release, $this->config->release->editor->edit['id'], $this->post->uid); $this->dao->update(TABLE_RELEASE)->data($release) ->autoCheck() ->batchCheck($this->config->release->edit->requiredFields, 'notempty') diff --git a/module/story/control.php b/module/story/control.php index e3c8909f7d..534d8c3cf3 100644 --- a/module/story/control.php +++ b/module/story/control.php @@ -1471,7 +1471,7 @@ class story extends control { foreach($relatedFiles[$story->id] as $file) { - $fileURL = common::getSysURL() . $this->file->webPath . $file->pathname; + $fileURL = common::getSysURL() . $this->file->webPath . $this->file->getRealPathName($file->pathname); $story->files .= html::a($fileURL, $file->title, '_blank') . '
'; } } diff --git a/module/story/model.php b/module/story/model.php index c60dc95510..5710a5db37 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -33,7 +33,7 @@ class storyModel extends model $story->spec = isset($spec->spec) ? $spec->spec : ''; $story->verify = isset($spec->verify) ? $spec->verify : ''; - $story = $this->loadModel('file')->revertRealSRC($story, 'spec,verify'); + $story = $this->loadModel('file')->replaceImgURL($story, 'spec,verify'); if($setImgSize) $story->spec = $this->file->setImgSize($story->spec); if($setImgSize) $story->verify = $this->file->setImgSize($story->verify); @@ -168,7 +168,7 @@ class storyModel extends model if($this->checkForceReview()) $story->status = 'draft'; if($story->status == 'draft') $story->stage = $this->post->plan > 0 ? 'planned' : 'wait'; - $story = $this->loadModel('file')->processEditor($story, $this->config->story->editor->create['id'], $this->post->uid); + $story = $this->loadModel('file')->processImgURL($story, $this->config->story->editor->create['id'], $this->post->uid); $this->dao->insert(TABLE_STORY)->data($story, 'spec,verify')->autoCheck()->batchCheck($this->config->story->create->requiredFields, 'notempty')->exec(); if(!dao::isError()) { @@ -319,7 +319,7 @@ class storyModel extends model $realPath = $file['realpath']; unset($file['realpath']); - if(rename($realPath, $this->file->savePath . $file['pathname'])) + if(rename($realPath, $this->file->savePath . $this->file->getSaveName($file['pathname']))) { $file['addedBy'] = $this->app->user->account; $file['addedDate'] = $now; @@ -328,7 +328,7 @@ class storyModel extends model $this->dao->insert(TABLE_FILE)->data($file)->exec(); $fileID = $this->dao->lastInsertID(); - $specData->spec .= ''; + $specData->spec .= ''; } else { @@ -399,7 +399,7 @@ class storyModel extends model ->remove('files,labels,comment,needNotReview,uid') ->get(); if($this->checkForceReview()) $story->status = 'changed'; - $story = $this->loadModel('file')->processEditor($story, $this->config->story->editor->change['id'], $this->post->uid); + $story = $this->loadModel('file')->processImgURL($story, $this->config->story->editor->change['id'], $this->post->uid); $this->dao->update(TABLE_STORY)->data($story, 'spec,verify') ->autoCheck() ->batchCheck($this->config->story->change->requiredFields, 'notempty') diff --git a/module/task/control.php b/module/task/control.php index bfe5ca9eb5..52b99f8a27 100644 --- a/module/task/control.php +++ b/module/task/control.php @@ -1207,7 +1207,7 @@ class task extends control $task->files = ''; foreach($relatedFiles[$task->id] as $file) { - $fileURL = common::getSysURL() . $this->file->webPath . $file->pathname; + $fileURL = common::getSysURL() . $this->file->webPath . $this->file->getRealPathName($file->pathname); $task->files .= html::a($fileURL, $file->title, '_blank') . '
'; } } diff --git a/module/task/model.php b/module/task/model.php index 4ffd779a06..cc505da222 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -59,7 +59,7 @@ class taskModel extends model } } - $task = $this->file->processEditor($task, $this->config->task->editor->create['id'], $this->post->uid); + $task = $this->file->processImgURL($task, $this->config->task->editor->create['id'], $this->post->uid); $this->dao->insert(TABLE_TASK)->data($task) ->autoCheck() ->batchCheck($this->config->task->create->requiredFields, 'notempty') @@ -246,7 +246,7 @@ class taskModel extends model $this->addTaskEstimate($estimate); } - $task = $this->loadModel('file')->processEditor($task, $this->config->task->editor->edit['id'], $this->post->uid); + $task = $this->loadModel('file')->processImgURL($task, $this->config->task->editor->edit['id'], $this->post->uid); $this->dao->update(TABLE_TASK)->data($task) ->autoCheck() ->batchCheckIF($task->status != 'cancel', $this->config->task->edit->requiredFields, 'notempty') @@ -809,7 +809,7 @@ class taskModel extends model ->fetch(); if(!$task) return false; - $task = $this->loadModel('file')->revertRealSRC($task, 'desc'); + $task = $this->loadModel('file')->replaceImgURL($task, 'desc'); if($setImgSize) $task->desc = $this->file->setImgSize($task->desc); if($task->assignedTo == 'closed') $task->assignedToRealName = 'Closed'; foreach($task as $key => $value) if(strpos($key, 'Date') !== false and !(int)substr($value, 0, 4)) $task->$key = ''; diff --git a/module/testreport/model.php b/module/testreport/model.php index 2ab9836681..d33a3b0bee 100644 --- a/module/testreport/model.php +++ b/module/testreport/model.php @@ -90,7 +90,7 @@ class testreportModel extends model ->remove('files,labels,uid') ->get(); - $data = $this->loadModel('file')->processEditor($date, $this->config->testreport->editor->create['id'], $this->post->uid); + $data = $this->loadModel('file')->processImgURL($date, $this->config->testreport->editor->create['id'], $this->post->uid); $this->dao->insert(TABLE_TESTREPORT)->data($data)->autocheck() ->batchCheck($this->config->testreport->create->requiredFields, 'notempty') ->batchCheck('start,end', 'notempty') @@ -122,7 +122,7 @@ class testreportModel extends model ->join('members', ',') ->remove('files,labels,uid') ->get(); - $data = $this->loadModel('file')->processEditor($date, $this->config->testreport->editor->edit['id'], $this->post->uid); + $data = $this->loadModel('file')->processImgURL($date, $this->config->testreport->editor->edit['id'], $this->post->uid); $this->dao->update(TABLE_TESTREPORT)->data($data)->autocheck() ->batchCheck($this->config->testreport->edit->requiredFields, 'notempty') ->batchCheck('start,end', 'notempty') @@ -145,7 +145,7 @@ class testreportModel extends model public function getById($reportID) { $report = $this->dao->select('*')->from(TABLE_TESTREPORT)->where('id')->eq($reportID)->fetch(); - $report = $this->loadModel('file')->revertRealSRC($report, 'report'); + $report = $this->loadModel('file')->replaceImgURL($report, 'report'); $report->files = $this->file->getByObject('testreport', $reportID); return $report; } diff --git a/module/testsuite/model.php b/module/testsuite/model.php index 670a726735..557b4231ea 100644 --- a/module/testsuite/model.php +++ b/module/testsuite/model.php @@ -133,7 +133,7 @@ class testsuiteModel extends model ->add('addedDate', helper::now()) ->remove('uid') ->get(); - $suite = $this->loadModel('file')->processEditor($suite, $this->config->testsuite->editor->create['id'], $this->post->uid); + $suite = $this->loadModel('file')->processImgURL($suite, $this->config->testsuite->editor->create['id'], $this->post->uid); $this->dao->insert(TABLE_TESTSUITE)->data($suite) ->batchcheck($this->config->testsuite->create->requiredFields, 'notempty') ->exec(); @@ -177,7 +177,7 @@ class testsuiteModel extends model public function getById($suiteID, $setImgSize = false) { $suite = $this->dao->select("*")->from(TABLE_TESTSUITE)->where('id')->eq((int)$suiteID)->fetch(); - $suite = $this->loadModel('file')->revertRealSRC($suite, 'desc'); + $suite = $this->loadModel('file')->replaceImgURL($suite, 'desc'); if($setImgSize) $suite->desc = $this->file->setImgSize($suite->desc); return $suite; } @@ -198,7 +198,7 @@ class testsuiteModel extends model ->add('lastEditedDate', helper::now()) ->remove('uid') ->get(); - $suite = $this->loadModel('file')->processEditor($suite, $this->config->testsuite->editor->edit['id'], $this->post->uid); + $suite = $this->loadModel('file')->processImgURL($suite, $this->config->testsuite->editor->edit['id'], $this->post->uid); $this->dao->update(TABLE_TESTSUITE)->data($suite) ->autoCheck() ->batchcheck($this->config->testsuite->edit->requiredFields, 'notempty') @@ -352,7 +352,7 @@ class testsuiteModel extends model ->add('addedDate', helper::now()) ->remove('uid') ->get(); - $lib = $this->loadModel('file')->processEditor($lib, $this->config->testsuite->editor->create['id'], $this->post->uid); + $lib = $this->loadModel('file')->processImgURL($lib, $this->config->testsuite->editor->create['id'], $this->post->uid); $this->dao->insert(TABLE_TESTSUITE)->data($lib) ->batchcheck($this->config->testsuite->createlib->requiredFields, 'notempty') ->check('name', 'unique', "deleted = '0'") diff --git a/module/testtask/model.php b/module/testtask/model.php index 3e9de631ab..b1db7f91e3 100644 --- a/module/testtask/model.php +++ b/module/testtask/model.php @@ -72,7 +72,7 @@ class testtaskModel extends model function create() { $task = fixer::input('post')->stripTags($this->config->testtask->editor->create['id'], $this->config->allowedTags)->join('mailto', ',')->remove('uid')->get(); - $task = $this->loadModel('file')->processEditor($task, $this->config->testtask->editor->create['id'], $this->post->uid); + $task = $this->loadModel('file')->processImgURL($task, $this->config->testtask->editor->create['id'], $this->post->uid); $this->dao->insert(TABLE_TESTTASK)->data($task) ->autoCheck($skipFields = 'begin,end') ->batchcheck($this->config->testtask->create->requiredFields, 'notempty') @@ -186,7 +186,7 @@ class testtaskModel extends model ->where('t1.id')->eq((int)$taskID) ->andWhere('t5.product = t1.product') ->fetch(); - $task = $this->loadModel('file')->revertRealSRC($task, 'desc'); + $task = $this->loadModel('file')->replaceImgURL($task, 'desc'); if($setImgSize) $task->desc = $this->loadModel('file')->setImgSize($task->desc); return $task; } @@ -521,7 +521,7 @@ class testtaskModel extends model { $oldTask = $this->dao->select("*")->from(TABLE_TESTTASK)->where('id')->eq((int)$taskID)->fetch(); $task = fixer::input('post')->stripTags($this->config->testtask->editor->edit['id'], $this->config->allowedTags)->join('mailto', ',')->remove('uid')->get(); - $task = $this->loadModel('file')->processEditor($task, $this->config->testtask->editor->edit['id'], $this->post->uid); + $task = $this->loadModel('file')->processImgURL($task, $this->config->testtask->editor->edit['id'], $this->post->uid); $this->dao->update(TABLE_TESTTASK)->data($task) ->autoCheck() ->batchcheck($this->config->testtask->edit->requiredFields, 'notempty') @@ -573,7 +573,7 @@ class testtaskModel extends model ->remove('comment,uid') ->get(); - $testtask = $this->loadModel('file')->processEditor($testtask, $this->config->testtask->editor->close['id'], $this->post->uid); + $testtask = $this->loadModel('file')->processImgURL($testtask, $this->config->testtask->editor->close['id'], $this->post->uid); $this->dao->update(TABLE_TESTTASK)->data($testtask) ->autoCheck() ->where('id')->eq((int)$taskID) @@ -1009,8 +1009,9 @@ class testtaskModel extends model $stepFiles = array(); foreach($files as $file) { - $file->webPath = $this->file->webPath . $file->pathname; - $file->realPath = $this->app->getAppRoot() . "www/data/upload/{$this->app->company->id}/" . $file->pathname; + $pathName = $this->file->getRealPathName($file->pathname); + $file->webPath = $this->file->webPath . $pathName; + $file->realPath = $this->file->savePath . $pathName; if($file->objectType == 'caseResult') { $resultFiles[$file->objectID][$file->id] = $file; diff --git a/module/todo/model.php b/module/todo/model.php index 81dcec6dc8..02edceb6f1 100644 --- a/module/todo/model.php +++ b/module/todo/model.php @@ -35,7 +35,7 @@ class todoModel extends model ->stripTags($this->config->todo->editor->create['id'], $this->config->allowedTags) ->remove('bug, task,uid') ->get(); - $todo = $this->loadModel('file')->processEditor($todo, $this->config->todo->editor->create['id'], $this->post->uid); + $todo = $this->loadModel('file')->processImgURL($todo, $this->config->todo->editor->create['id'], $this->post->uid); $this->dao->insert(TABLE_TODO)->data($todo) ->autoCheck() ->checkIF($todo->type == 'custom', $this->config->todo->create->requiredFields, 'notempty') @@ -126,7 +126,7 @@ class todoModel extends model ->stripTags($this->config->todo->editor->edit['id'], $this->config->allowedTags) ->remove('uid') ->get(); - $todo = $this->loadModel('file')->processEditor($todo, $this->config->todo->editor->edit['id'], $this->post->uid); + $todo = $this->loadModel('file')->processImgURL($todo, $this->config->todo->editor->edit['id'], $this->post->uid); $this->dao->update(TABLE_TODO)->data($todo) ->autoCheck() ->checkIF($todo->type == 'custom', $this->config->todo->edit->requiredFields, 'notempty') @@ -227,7 +227,7 @@ class todoModel extends model { $todo = $this->dao->findById((int)$todoID)->from(TABLE_TODO)->fetch(); if(!$todo) return false; - $todo = $this->loadModel('file')->revertRealSRC($todo, 'desc'); + $todo = $this->loadModel('file')->replaceImgURL($todo, 'desc'); if($setImgSize) $todo->desc = $this->file->setImgSize($todo->desc); if($todo->type == 'task') $todo->name = $this->dao->findById($todo->idvalue)->from(TABLE_TASK)->fetch('name'); if($todo->type == 'bug') $todo->name = $this->dao->findById($todo->idvalue)->from(TABLE_BUG)->fetch('title');