1
This commit is contained in:
@@ -1420,7 +1420,8 @@ class Article extends Base
|
||||
|
||||
//为预接收的文章生成production实例
|
||||
if($data['state'] == 6){
|
||||
$this->addProductionEx($data['articleId']);
|
||||
// $this->addProductionEx($data['articleId']);
|
||||
$this->addArticleMainEx($data['articleId']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2001,7 +2002,17 @@ class Article extends Base
|
||||
return jsonSuccess($re);
|
||||
}
|
||||
|
||||
public function myMarkTmage(){
|
||||
$data = $this->request->post();
|
||||
$rule = new Validate([
|
||||
"article_id"=>"require"
|
||||
]);
|
||||
if(!$rule->check($data)){
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
$this->markArticleImage($data['article_id']);
|
||||
|
||||
}
|
||||
|
||||
/**分解文章的图片和表格
|
||||
* @return void
|
||||
@@ -2020,7 +2031,7 @@ class Article extends Base
|
||||
}
|
||||
$this->markWord("https://submission.tmrjournals.com/public/".$file,$article_id);
|
||||
//处理压缩包等等的内容
|
||||
$pics = $this->article_file_obj->where("article_id",$article_id)->where("type_name","picturesAndTables")->where("state",0)->select();
|
||||
$pics = $this->article_file_obj->where("article_id",$article_id)->where("type_name","picturesAndTables")->where("state",0)->order("file_id desc")->limit(1)->select();
|
||||
foreach ($pics as $v){
|
||||
$extension = pathinfo($v['file_url'], PATHINFO_EXTENSION);
|
||||
if($extension=="zip"){
|
||||
@@ -2032,57 +2043,200 @@ class Article extends Base
|
||||
|
||||
|
||||
|
||||
private function markZip($file,$article_id){
|
||||
$article_info = $this->article_obj->where("article_id",$article_id)->find();
|
||||
// private function markZip($file,$article_id){
|
||||
// $article_info = $this->article_obj->where("article_id",$article_id)->find();
|
||||
// $zip = new \ZipArchive();
|
||||
// // 打开 ZIP 文件
|
||||
// if ($zip->open($file) === true) {
|
||||
// $fileCount = $zip->numFiles;
|
||||
// $num_rand = rand(1000,9999);
|
||||
// for ($i = 0; $i < $fileCount; $i++) {
|
||||
// $stat = $zip->statIndex($i);
|
||||
// $fileName = $stat['name'];
|
||||
// $fileContent = $zip->getFromIndex($i);
|
||||
// $base_url = ROOT_PATH."public/articleImage/".$article_id."/";
|
||||
// $extension = pathinfo($fileName, PATHINFO_EXTENSION);
|
||||
// if($extension=="jpg"||$extension=="JPG"||$extension=="jpeg"){
|
||||
// file_put_contents($base_url."zipimg".$num_rand.$i.".jpg", $fileContent);
|
||||
// $insert['article_id'] = $article_id;
|
||||
// $insert['image'] = $article_id."/"."zipimg".$num_rand.$i.".jpg";
|
||||
// $insert['ctime'] = time();
|
||||
// $this->article_image_obj->insert($insert);
|
||||
// }elseif ($extension=="png"){
|
||||
// file_put_contents($base_url."zipimg".$num_rand.$i.".png", $fileContent);
|
||||
// $insert['article_id'] = $article_id;
|
||||
// $insert['image'] = $article_id."/"."zipimg".$num_rand.$i.".png";
|
||||
// $insert['ctime'] = time();
|
||||
// $this->article_image_obj->insert($insert);
|
||||
// }elseif ($extension=="tiff"||$extension=="tif"){
|
||||
// file_put_contents($base_url."zipimg".$num_rand.$i.".".$extension, $fileContent);
|
||||
// $imagick = new \Imagick();
|
||||
// $imagick->readImage($fileContent);
|
||||
// $imagick->setImageFormat('jpg');
|
||||
// $imagick->writeImage($base_url."zipimg".$num_rand.$i.".jpg");
|
||||
// $imagick->clear();
|
||||
// $imagick->destroy();
|
||||
// $insert['article_id'] = $article_id;
|
||||
// $insert['image'] = $article_id."/"."zipimg".$num_rand.$i.".".$extension;
|
||||
// $insert['jpg_url'] = $article_id."/"."zipimg".$num_rand.$i.".jpg";
|
||||
// $insert['ctime'] = time();
|
||||
// $this->article_image_obj->insert($insert);
|
||||
// }elseif ($extension=="emf"||$extension=="EMF"){
|
||||
// file_put_contents($base_url."zipimg".$num_rand.$i.".".$extension, $fileContent);
|
||||
// $imagick = new \Imagick();
|
||||
// $imagick->readImage($fileContent);
|
||||
// $imagick->setImageFormat('jpg');
|
||||
// $imagick->writeImage($base_url."zipimg".$num_rand.$i.".jpg");
|
||||
// $imagick->clear();
|
||||
// $imagick->destroy();
|
||||
// $insert['article_id'] = $article_id;
|
||||
// $insert['image'] = $article_id."/"."zipimg".$num_rand.$i.".".$extension;
|
||||
// $insert['jpg_url'] = $article_id."/"."zipimg".$num_rand.$i.".jpg";
|
||||
// $insert['ctime'] = time();
|
||||
// $this->article_image_obj->insert($insert);
|
||||
// }elseif ($extension=="docx"){
|
||||
// $word_dir = ROOT_PATH."public/articleCache/".$article_id;
|
||||
// if (!is_dir($word_dir)) {
|
||||
// mkdir($word_dir, 0777, true);
|
||||
// }
|
||||
// $word_file = rand(1000,9999).$fileName;
|
||||
// file_put_contents($word_dir."/".$word_file, $fileContent);
|
||||
// $this->markWord("https://submission.tmrjournals.com/public/articleCache/".$article_id."/".$word_file,$article_id);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// // 关闭 ZIP 文件
|
||||
// $zip->close();
|
||||
//
|
||||
// } else {
|
||||
// return json(['error' => 'Unable to open ZIP file.']);
|
||||
// }
|
||||
// }
|
||||
private function markZip($file, $article_id)
|
||||
{
|
||||
$article_info = $this->article_obj->where("article_id", $article_id)->find();
|
||||
$zip = new \ZipArchive();
|
||||
|
||||
// 打开 ZIP 文件
|
||||
if ($zip->open($file) === true) {
|
||||
$fileCount = $zip->numFiles;
|
||||
$num_rand = rand(1000,9999);
|
||||
$num_rand = uniqid('', true); // 使用 uniqid 来生成更唯一的文件名
|
||||
|
||||
for ($i = 0; $i < $fileCount; $i++) {
|
||||
$stat = $zip->statIndex($i);
|
||||
$fileName = $stat['name'];
|
||||
$fileName = basename($stat['name']); // 获取文件名并去掉路径
|
||||
$fileContent = $zip->getFromIndex($i);
|
||||
$base_url = ROOT_PATH."public/articleImage/".$article_id."/";
|
||||
$base_url = ROOT_PATH . "public/articleImage/" . $article_id . "/";
|
||||
$extension = pathinfo($fileName, PATHINFO_EXTENSION);
|
||||
if($extension=="jpg"||$extension=="JPG"||$extension=="jpeg"){
|
||||
file_put_contents($base_url."zipimg".$num_rand.$i.".jpg", $fileContent);
|
||||
$insert['article_id'] = $article_id;
|
||||
$insert['image'] = $article_id."/"."zipimg".$num_rand.$i.".jpg";
|
||||
$insert['ctime'] = time();
|
||||
$this->article_image_obj->insert($insert);
|
||||
}elseif ($extension=="png"){
|
||||
file_put_contents($base_url."zipimg".$num_rand.$i.".png", $fileContent);
|
||||
$insert['article_id'] = $article_id;
|
||||
$insert['image'] = $article_id."/"."zipimg".$num_rand.$i.".png";
|
||||
$insert['ctime'] = time();
|
||||
$this->article_image_obj->insert($insert);
|
||||
}elseif ($extension=="tiff"){
|
||||
file_put_contents($base_url."zipimg".$num_rand.$i.".tiff", $fileContent);
|
||||
$insert['article_id'] = $article_id;
|
||||
$insert['image'] = $article_id."/"."zipimg".$num_rand.$i.".tiff";
|
||||
$insert['ctime'] = time();
|
||||
$this->article_image_obj->insert($insert);
|
||||
}elseif ($extension=="docx"){
|
||||
$word_dir = ROOT_PATH."public/articleCache/".$article_id;
|
||||
if (!is_dir($word_dir)) {
|
||||
mkdir($word_dir, 0777, true);
|
||||
}
|
||||
$word_file = rand(1000,9999).$fileName;
|
||||
file_put_contents($word_dir."/".$word_file, $fileContent);
|
||||
$this->markWord("https://submission.tmrjournals.com/public/articleCache/".$article_id."/".$word_file,$article_id);
|
||||
}
|
||||
|
||||
// 创建文件名并确保唯一性
|
||||
$newFileName = "zipimg" . $num_rand . $i . '.' . $extension;
|
||||
|
||||
if (in_array(strtolower($extension), ['jpg', 'jpeg', 'png'])) {
|
||||
// 处理图片文件
|
||||
file_put_contents($base_url . $newFileName, $fileContent);
|
||||
$this->insertImageData($article_id, $newFileName);
|
||||
} elseif (in_array(strtolower($extension), ['tiff', 'tif'])) {
|
||||
// 处理 TIFF 和 EMF 文件并转换为 JPG
|
||||
file_put_contents($base_url . $newFileName, $fileContent);
|
||||
$this->insertImageData($article_id, $newFileName);
|
||||
// $this->convertImageToJpg($base_url . $newFileName, $base_url, $num_rand, $i, $extension, $article_id);
|
||||
} elseif ($extension == "docx") {
|
||||
// 处理 DOCX 文件
|
||||
$this->handleDocxFile($fileContent, $article_id, $fileName);
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭 ZIP 文件
|
||||
$zip->close();
|
||||
|
||||
} else {
|
||||
return json(['error' => 'Unable to open ZIP file.']);
|
||||
}
|
||||
}
|
||||
|
||||
private function insertImageData($article_id, $newFileName)
|
||||
{
|
||||
$insert = [
|
||||
'article_id' => $article_id,
|
||||
'image' => $article_id . "/" . $newFileName,
|
||||
'ctime' => time(),
|
||||
];
|
||||
$this->article_image_obj->insert($insert);
|
||||
}
|
||||
|
||||
|
||||
private function convertImageToJpg($inputPath, $base_url, $num_rand, $index, $extension, $article_id)
|
||||
{
|
||||
try {
|
||||
$imagick = new \Imagick();
|
||||
|
||||
// 确保文件读取成功
|
||||
$imagick->readImage($inputPath);
|
||||
$outputPath = $base_url . "zipimg" . $num_rand . $index . ".jpg";
|
||||
// 确保转换成功并写入文件
|
||||
if ($imagick->setImageFormat('jpg') && $imagick->writeImage($outputPath)) {
|
||||
echo "Image successfully written to: " . $outputPath; // Debugging output
|
||||
$imagick->clear();
|
||||
$imagick->destroy();
|
||||
|
||||
// 插入数据库记录
|
||||
$insert = [
|
||||
'article_id' => $article_id,
|
||||
'image' => $article_id . "/zipimg" . $num_rand . $index . '.' . $extension,
|
||||
'jpg_url' => $article_id . "/zipimg" . $num_rand . $index . ".jpg",
|
||||
'ctime' => time(),
|
||||
];
|
||||
$this->article_image_obj->insert($insert);
|
||||
} else {
|
||||
echo "Image writing failed!"; // Debugging output
|
||||
}
|
||||
} catch (\ImagickException $e) {
|
||||
// 错误处理,输出异常信息
|
||||
return json(['error' => 'Image conversion failed: ' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
// private function convertImageToJpg($inputPath, $base_url, $num_rand, $index, $extension, $article_id)
|
||||
// {
|
||||
// try {
|
||||
// $imagick = new \Imagick();
|
||||
// $imagick->readImage($inputPath);
|
||||
// $imagick->setImageFormat('jpg');
|
||||
// $outputPath = $base_url . "zipimg" . $num_rand . $index . ".jpg";
|
||||
// $res = $imagick->writeImage($outputPath);
|
||||
// var_dump($res);
|
||||
//
|
||||
// $imagick->clear();
|
||||
// $imagick->destroy();
|
||||
//
|
||||
// // 插入数据库记录
|
||||
// $insert = [
|
||||
// 'article_id' => $article_id,
|
||||
// 'image' => $article_id . "/zipimg" . $num_rand . $index . '.' . $extension,
|
||||
// 'jpg_url' => $article_id . "/zipimg" . $num_rand . $index . ".jpg",
|
||||
// 'ctime' => time(),
|
||||
// ];
|
||||
// $this->article_image_obj->insert($insert);
|
||||
// } catch (\Exception $e) {
|
||||
// // 错误处理,可以记录日志或返回错误信息
|
||||
// return json(['error' => 'Image conversion failed: ' . $e->getMessage()]);
|
||||
// }
|
||||
// }
|
||||
|
||||
private function handleDocxFile($fileContent, $article_id, $fileName)
|
||||
{
|
||||
$word_dir = ROOT_PATH . "public/articleCache/" . $article_id;
|
||||
if (!is_dir($word_dir)) {
|
||||
mkdir($word_dir, 0777, true);
|
||||
}
|
||||
|
||||
$word_file = rand(1000, 9999) . $fileName;
|
||||
file_put_contents($word_dir . "/" . $word_file, $fileContent);
|
||||
|
||||
$this->markWord("https://submission.tmrjournals.com/public/articleCache/" . $article_id . "/" . $word_file, $article_id);
|
||||
}
|
||||
|
||||
private function markWord($file,$article_id){
|
||||
$url = $this->ts_base_url."api/typeset/markImages";
|
||||
$program['file'] = $file;
|
||||
@@ -2096,12 +2250,42 @@ class Article extends Base
|
||||
foreach ($file_runs as $v){
|
||||
$insert['article_id'] = $article_id;
|
||||
$insert['image'] = $article_id."/".$v;
|
||||
// if(strtolower(pathinfo($v,PATHINFO_EXTENSION))=="emf"){
|
||||
// $imagick = new \Imagick();
|
||||
// $formats = $imagick->queryFormats();
|
||||
//// var_dump($formats);die;
|
||||
// $inputPath = ROOT_PATH."public/articleImage/".$article_id."/".$v;
|
||||
// // 确保文件读取成功
|
||||
// $imagick->readImage($inputPath);
|
||||
// $outputPath = ROOT_PATH."public/articleImage/".$article_id."/".substr($v,0,-3)."jpg";;
|
||||
// // 确保转换成功并写入文件
|
||||
// if ($imagick->setImageFormat('jpg') && $imagick->writeImage($outputPath)) {
|
||||
// echo "Image successfully written to: " . $outputPath; // Debugging output
|
||||
// $imagick->clear();
|
||||
// $imagick->destroy();
|
||||
// $insert['jpg_url'] = $article_id."/".substr($v,0,-3)."jpg";
|
||||
// } else {
|
||||
// echo "Image writing failed!"; // Debugging output
|
||||
// }
|
||||
// }
|
||||
$insert['ctime'] = time();
|
||||
$this->article_image_obj->insert($insert);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function testArticleImageEx(){
|
||||
$data = $this->request->post();
|
||||
$rule = new Validate([
|
||||
"article_id"=>"require"
|
||||
]);
|
||||
if(!$rule->check($data)){
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
$this->addArticleMainEx($data['article_id']);
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
|
||||
public function getArticleImages(){
|
||||
$data = $this->request->post();
|
||||
|
||||
Reference in New Issue
Block a user