From 5bd2e2e0243cf3cc974a065cb5fdaa205c11d380 Mon Sep 17 00:00:00 2001 From: wangjinlei <751475802@qq.com> Date: Tue, 3 Dec 2024 17:08:40 +0800 Subject: [PATCH] 1 --- application/api/controller/Article.php | 33 +++++++++++++++ application/api/controller/Base.php | 2 +- application/api/controller/Reviewer.php | 4 +- application/api/controller/User.php | 2 +- application/common.php | 56 +++++++++++++++++++++++++ composer.json | 2 +- vendor/composer/installed.php | 4 +- 7 files changed, 96 insertions(+), 7 deletions(-) diff --git a/application/api/controller/Article.php b/application/api/controller/Article.php index 94725c4..0f9de52 100644 --- a/application/api/controller/Article.php +++ b/application/api/controller/Article.php @@ -6,6 +6,7 @@ use app\api\controller\Base; use think\Db; use think\Queue; use think\Validate; +use PhpOffice\PhpWord\IOFactory; /** * @title 文章接口 @@ -1905,6 +1906,38 @@ class Article extends Base return json(['code' => 0]); } + + /**分解文章的图片和表格 + * @return void + */ + public function markArticleImgTab(){ + $data = $this->request->post(); + $rule = new Validate([ + "article_id"=>"require" + ]); + if(!$rule->check($data)){ + return jsonError($rule->getError()); + } + $article_info = $this->article_obj->where("article_id",$data['article_id'])->find(); + $files = $this->article_file_obj->where("article_id",$data['article_id'])->where("type_name","manuscirpt")->where("state",0)->order("ctme desc")->limit(1)->select(); + if(isset($files[0])){ + $file = $files[0]['file_url']; + } + $dir = ROOT_PATH."public/articleImage/".$article_info['accept_sn']; + if (!is_dir($dir)) { + mkdir($dir, 0777, true); + } + $url = $this->ts_base_url."api/typeset/markImages"; + $program['url'] = "https://submission.tmrjournals.com/public/".$files; + $program['sn'] = $article_info['accept_sn']; + $res = object_to_array(json_decode(myPost($url, $program))); + $file_runs = $res['list']; + return jsonSuccess($file_runs); + } + + + + /** * 编辑添加审稿实例(临时开启,为了补充审稿实例不够) */ diff --git a/application/api/controller/Base.php b/application/api/controller/Base.php index cf2bab2..11f1490 100644 --- a/application/api/controller/Base.php +++ b/application/api/controller/Base.php @@ -9,7 +9,7 @@ use hashids\hashids; class Base extends Controller { - protected $ts_base_url = "http://ts.tmrjournals.cn/"; + protected $ts_base_url = "http://ts.tmrjournals.com/"; protected $user_obj = ''; protected $captcha_obj = ''; diff --git a/application/api/controller/Reviewer.php b/application/api/controller/Reviewer.php index 787ac9f..f15fe4a 100644 --- a/application/api/controller/Reviewer.php +++ b/application/api/controller/Reviewer.php @@ -849,7 +849,7 @@ class Reviewer extends Base if(preg_match('/[\x{4e00}-\x{9fa5}]/u', $content)>0){//含有中文 if($journal_info['journal_id']==1){ if(mb_strlen($content, 'UTF8')<150){ - return jsonError("We encourage you to enrich your comment further to help improve the peer paper (at least 100 words)."); + return jsonError("We encourage you to enrich your comment further to help improve the peer paper (at least 150 words)."); } }else{ if(mb_strlen($content, 'UTF8')<100){ @@ -860,7 +860,7 @@ class Reviewer extends Base if($journal_info['journal_id']==1){ $carray = explode(" ", $content); if(count($carray)<150){ - return jsonError("We encourage you to enrich your comment further to help improve the peer paper (at least 100 words)."); + return jsonError("We encourage you to enrich your comment further to help improve the peer paper (at least 150 words)."); } }else{ $carray = explode(" ", $content); diff --git a/application/api/controller/User.php b/application/api/controller/User.php index b41a241..69fa52b 100644 --- a/application/api/controller/User.php +++ b/application/api/controller/User.php @@ -1898,7 +1898,7 @@ class User extends Base $user_info = $this->user_obj->where('account', $account)->find(); if ($user_info['type'] == 2) { $ros[] = 'editor'; - if($account=="liuna"){ + if($account=="liuna"||$account=="zhuwenjing"){ $ros[] = "superadmin"; } return $ros; diff --git a/application/common.php b/application/common.php index 0903709..5dfa07f 100644 --- a/application/common.php +++ b/application/common.php @@ -4,6 +4,7 @@ use PHPMailer\PHPMailer\PHPMailer; use think\Db; use think\Env; use think\Cache; +use PhpOffice\PhpWord\IOFactory; //use TCPDF; @@ -172,6 +173,61 @@ function proofState($article_id) $p_article_obj->where('article_id', $article_id)->where('state', '<>', 1)->where('proof_etime', '<', time())->where('proof_state', 1)->update(['proof_state' => 2]); } +function readWordImg($article_id,$file){ + $phpWord = IOFactory::load($file); + +// 获取文档中的所有图像 + $images = []; + foreach ($phpWord->getSections() as $section) { + foreach ($section->getElements() as $element) { + var_dump(get_class($element)); // 输出每个元素的类名 + + // 如果是列表项元素,检查其中是否包含图片 + if ($element instanceof \PhpOffice\PhpWord\Element\ListItemRun) { + foreach ($element->getElements() as $itemElement) { + if (method_exists($itemElement, 'getImage')) { + $image = $itemElement->getImage(); + if ($image) { + $imageContent = $image->getImageString(); + $imageName = 'image_' . uniqid() . '.' . $image->getExtension(); + file_put_contents(ROOT_PATH.'/public/articleImage/'.$article_id."/" . $imageName, $imageContent); + $images[] = $imageName; + } + } + } + } elseif ($element instanceof \PhpOffice\PhpWord\Element\Table) { + // 检查表格中是否包含图片 + foreach ($element->getRows() as $row) { + foreach ($row->getCells() as $cell) { + foreach ($cell->getElements() as $cellElement) { + if (method_exists($cellElement, 'getImage')) { + $image = $cellElement->getImage(); + if ($image) { + $imageContent = $image->getImageString(); + $imageName = 'image_' . uniqid() . '.' . $image->getExtension(); + file_put_contents(ROOT_PATH.'/public/articleImage/'.$article_id."/" . $imageName, $imageContent); + $images[] = $imageName; + } + } + } + } + } + } + // 检查是否是图片元素 + elseif (method_exists($element, 'getImage')) { + $image = $element->getImage(); + if ($image) { + $imageContent = $image->getImageString(); + $imageName = 'image_' . uniqid() . '.' . $image->getExtension(); + file_put_contents(ROOT_PATH.'/public/articleImage/'.$article_id."/" . $imageName, $imageContent); + $images[] = $imageName; + } + } + } + } + return $images; +} + /** * 生成文章sn号 * @return type diff --git a/composer.json b/composer.json index 3f77820..1a91808 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "tecnickcom/tcpdf": "^6.3", "weiwei/api-doc": "^1.6", "topthink/think-queue": "1.1.4", - "phpoffice/phpword": "^1.0", + "phpoffice/phpword": "^1.2", "topthink/think-image": "^1.0", "mpdf/mpdf": "^8.1", "phpoffice/phpexcel": "^1.8", diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index d4364d9..6c93466 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => 'topthink/think', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '1f7220f36e66f33fb9d3867ecb1856a4d2fb0ae5', + 'reference' => '79de1c784a0e081dfa16d0bcd35779967aa0fd0a', 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -175,7 +175,7 @@ 'topthink/think' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '1f7220f36e66f33fb9d3867ecb1856a4d2fb0ae5', + 'reference' => '79de1c784a0e081dfa16d0bcd35779967aa0fd0a', 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(),