This commit is contained in:
王金磊
2023-03-30 11:44:37 +08:00
parent 34494929a6
commit e4be850ba1
14 changed files with 625 additions and 910 deletions

View File

@@ -15,7 +15,8 @@ use think\Env;
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
// 应用公共文件
function authcode($str) {
function authcode($str)
{
$key = substr(md5('ThinkPHP.CN'), 5, 8);
$str1 = substr(md5($str), 8, 10);
return md5($key . $str1);
@@ -33,7 +34,8 @@ function authcode($str) {
* @param $attachmentFile 附件 string | array
* @return array
*/
function sendEmail($email = '', $title = '', $from_name = '', $content = '', $memail = '', $mpassword = '', $attachmentFile = '') {
function sendEmail($email = '', $title = '', $from_name = '', $content = '', $memail = '', $mpassword = '', $attachmentFile = '')
{
date_default_timezone_set('PRC');
//Create a new PHPMailer instance
$mail = new PHPMailer;
@@ -72,7 +74,7 @@ function sendEmail($email = '', $title = '', $from_name = '', $content = '', $me
//组合邮件模板的头尾
$pre = Env::get('emailtemplete.pre');
$net = Env::get('emailtemplete.net');
$net = str_replace("{{email}}",$memail,$net);
$net = str_replace("{{email}}", $memail, $net);
// $mail->msgHTML($pre.$content.$net);
$mail->msgHTML($content);
@@ -80,21 +82,20 @@ function sendEmail($email = '', $title = '', $from_name = '', $content = '', $me
$mail->AltBody = '';
if (is_array($attachmentFile)) {
for ($i = 0; $i < count($attachmentFile); $i++) {
if($attachmentFile[$i]!=''){
$mail->addAttachment($attachmentFile[$i],substr($attachmentFile[$i],strrpos($attachmentFile[$i],DS)+1)); //这里可以是多维数组,然后循环附件的文件和名称
if ($attachmentFile[$i] != '') {
$mail->addAttachment($attachmentFile[$i], substr($attachmentFile[$i], strrpos($attachmentFile[$i], DS) + 1)); //这里可以是多维数组,然后循环附件的文件和名称
}
}
} else {
if ($attachmentFile != '') {
//Attach an image file
$mail->addAttachment($attachmentFile, substr($attachmentFile,strrpos($attachmentFile,DS)+1));
$mail->addAttachment($attachmentFile, substr($attachmentFile, strrpos($attachmentFile, DS) + 1));
}
}
//send the message, check for errors
if (!$mail->send()) {
$status = 0;
$data = "邮件发送失败" . $mail->ErrorInfo;
;
$data = "邮件发送失败" . $mail->ErrorInfo;;
} else {
$status = 1;
$data = "邮件发送成功";
@@ -102,7 +103,8 @@ function sendEmail($email = '', $title = '', $from_name = '', $content = '', $me
return ['status' => $status, 'data' => $data]; //返回值(可选)
}
function object_to_array($obj) {
function object_to_array($obj)
{
$obj = (array) $obj;
foreach ($obj as $k => $v) {
if (gettype($v) == 'resource') {
@@ -115,45 +117,47 @@ function object_to_array($obj) {
return $obj;
}
function get_str(){
function get_str()
{
$length = 32;
$str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$len = strlen($str)-1;
$randstr = '';
for ($i=0;$i<$length;$i++) {
$num=mt_rand(0,$len);
$len = strlen($str) - 1;
$randstr = '';
for ($i = 0; $i < $length; $i++) {
$num = mt_rand(0, $len);
$randstr .= $str[$num];
}
return md5($randstr.time());
}
return md5($randstr . time());
}
function getRandPassword(){
function getRandPassword()
{
$length = 8;
$str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$len = strlen($str)-1;
$randstr = '';
for ($i=0;$i<$length;$i++) {
$num=mt_rand(0,$len);
$len = strlen($str) - 1;
$randstr = '';
for ($i = 0; $i < $length; $i++) {
$num = mt_rand(0, $len);
$randstr .= $str[$num];
}
return $randstr;
}
return $randstr;
}
function proofState($article_id){
function proofState($article_id)
{
$p_article_obj = Db::name('production_article');
$p_article_obj->where('article_id',$article_id)->where('state','<>',1)->where('proof_etime','<',time())->where('proof_state',1)->update(['proof_state'=>2]);
$p_article_obj->where('article_id', $article_id)->where('state', '<>', 1)->where('proof_etime', '<', time())->where('proof_state', 1)->update(['proof_state' => 2]);
}
/**
* 生成文章sn号
* @return type
*/
function getArticleSN($abbr, $type) {
function getArticleSN($abbr, $type)
{
$str = $abbr;
$str .= date('Y', time()) . $type . date('md', time());
$where['accept_sn'] = ['like', "$str%"];
@@ -171,7 +175,8 @@ function getArticleSN($abbr, $type) {
return $str;
}
function translateType($type) {
function translateType($type)
{
$frag = '';
switch ($type) {
case "A":
@@ -244,9 +249,10 @@ function translateType($type) {
return $frag;
}
function search_array_val($arr,$val){
foreach($arr as $k => $v){
if($v == $val){
function search_array_val($arr, $val)
{
foreach ($arr as $k => $v) {
if ($v == $val) {
return $k;
}
}
@@ -256,76 +262,80 @@ function search_array_val($arr,$val){
* GET 请求
* @param string $url
*/
function myGet($url){
function myGet($url)
{
$oCurl = curl_init();
if(stripos($url,"https://")!==FALSE){
if (stripos($url, "https://") !== FALSE) {
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
}
curl_setopt($oCurl, CURLOPT_URL, $url);//目标URL
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );//设定是否显示头信息,1为显示
curl_setopt($oCurl, CURLOPT_BINARYTRANSFER, true) ;//在启用CURLOPT_RETURNTRANSFER时候将获取数据返回
curl_setopt($oCurl, CURLOPT_URL, $url); //目标URL
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); //设定是否显示头信息,1为显示
curl_setopt($oCurl, CURLOPT_BINARYTRANSFER, true); //在启用CURLOPT_RETURNTRANSFER时候将获取数据返回
$sContent = curl_exec($oCurl);
$aStatus = curl_getinfo($oCurl);//获取页面各种信息
$aStatus = curl_getinfo($oCurl); //获取页面各种信息
curl_close($oCurl);
if(intval($aStatus["http_code"])==200){
if (intval($aStatus["http_code"]) == 200) {
return $sContent;
}else{
} else {
return false;
}
}
function my_doiToFrag($data){
function my_doiToFrag($data)
{
$ts_refer_obj = Db::name('ts_refer');
if($data['refer_doi']==''){
if ($data['refer_doi'] == '') {
return 0;
}
$doi = str_replace('/','%2F',$data['refer_doi']);
$doi = str_replace('/', '%2F', $data['refer_doi']);
$url = "https://citation.crosscite.org/format?doi=$doi&style=american-veterinary-medical-association&lang=en-US";
$res = myGet($url);
$frag = trim(substr($res,strpos($res,'.')+1));
$frag = trim(substr($res, strpos($res, '.') + 1));
$f = '';
$cs = 0;
if($frag==""){
if ($frag == "") {
$f = $data['refer_content'];
}else{
$c_frag = rtrim($frag,'.');
$f = substr_replace($c_frag,PHP_EOL,strripos($c_frag,"http"),0);
} else {
$c_frag = rtrim($frag, '.');
$f = substr_replace($c_frag, PHP_EOL, strripos($c_frag, "http"), 0);
$cs = 1;
}
$ts_refer_obj->where('ts_refer_id',$data['ts_refer_id'])->update(['refer_frag'=>$f,"cs"=>$cs]);
$ts_refer_obj->where('ts_refer_id', $data['ts_refer_id'])->update(['refer_frag' => $f, "cs" => $cs]);
$ts_refer_obj->close();
}
function my_doiToFrag1($data){
function my_doiToFrag1($data)
{
$p_refer_obj = Db::name('production_article_refer');
if($data['refer_doi']==''){
if ($data['refer_doi'] == '') {
return 0;
}
$doi = str_replace('/','%2F',$data['refer_doi']);
$doi = str_replace('/', '%2F', $data['refer_doi']);
// $url = "https://citation.crosscite.org/format?doi=$doi&style=american-veterinary-medical-association&lang=en-US";
$url = "https://citation.crosscite.org/format?doi=$doi&style=cancer-translational-medicine&lang=en-US";
$res = myGet($url);
$frag = trim(substr($res,strpos($res,'.')+1));
$frag = trim(substr($res, strpos($res, '.') + 1));
$f = '';
$cs = 0;
if($frag==""){
if ($frag == "") {
$f = $data['refer_content'];
}else{
$c_frag = rtrim($frag,'.');
} else {
$c_frag = rtrim($frag, '.');
// $f = substr_replace($c_frag,PHP_EOL,strripos($c_frag,"http"),0);
$f = $c_frag." Available at: ".PHP_EOL."http://doi.org/".$data['refer_doi'];
$f = $c_frag . " Available at: " . PHP_EOL . "http://doi.org/" . $data['refer_doi'];
$cs = 1;
}
$p_refer_obj->where('p_refer_id',$data['p_refer_id'])->update(['refer_frag'=>$f,"cs"=>$cs]);
$p_refer_obj->where('p_refer_id', $data['p_refer_id'])->update(['refer_frag' => $f, "cs" => $cs]);
$p_refer_obj->close();
}
/**
* 增加用户积分log信息
*/
function addUserScoreLog($user_id,$score,$content,$ctime,$act='+'){
function addUserScoreLog($user_id, $score, $content, $ctime, $act = '+')
{
$score_obj = Db::name('user_score_log');
$insert['user_id'] = $user_id;
$insert['content'] = trim($content);
@@ -336,103 +346,143 @@ function addUserScoreLog($user_id,$score,$content,$ctime,$act='+'){
}
function my_doiToFrag2($data){
function my_doiToFrag2($data)
{
$p_refer_obj = Db::name('production_article_refer');
if($data['refer_doi']==''){
if ($data['refer_doi'] == '') {
return 0;
}
$doi = str_replace('/','%2F',$data['refer_doi']);
$doi = str_replace('/', '%2F', $data['refer_doi']);
// $url = "https://citation.crosscite.org/format?doi=$doi&style=american-veterinary-medical-association&lang=en-US";
$url = "https://citation.crosscite.org/format?doi=$doi&style=cancer-translational-medicine&lang=en-US";
$res = myGet($url);
$frag = trim(substr($res,strpos($res,'.')+1));
$frag = trim(substr($res, strpos($res, '.') + 1));
$update = [];
if($frag==""){
if ($frag == "") {
$update['refer_frag'] = $data['refer_content'];
}else{
} else {
// preg_match("/[0-9]{4}/",$frag,$math);
// $year = $math[0];
// $qbj=trim(substr($frag,0,stripos($frag,$year))) ;
if(mb_substr_count($frag,'.')!=3){
$f = $frag." Available at: ".PHP_EOL."http://doi.org/".$data['refer_doi'];
if (mb_substr_count($frag, '.') != 3) {
$f = $frag . " Available at: " . PHP_EOL . "http://doi.org/" . $data['refer_doi'];
$update['refer_frag'] = $f;
$update['cs'] = 1;
}else{
$res = explode('.',$frag);
} else {
$res = explode('.', $frag);
$update['author'] = prgeAuthor($res[0]);
$update['title'] = trim($res[1]);
$bj = bekjournal($res[2]);
$joura = formateJournal(trim($bj[0]));
$update['joura'] = $joura;
$is_js = 0;
if($joura==trim($bj[0])){
if ($joura == trim($bj[0])) {
}
$update['is_ja'] = $joura==trim($bj[0])?0:1;
$update['dateno'] = str_replace(' ','',str_replace('-','',trim($bj[1])));
$update['doilink'] = "http://doi.org/".$data['refer_doi'];
$update['is_ja'] = $joura == trim($bj[0]) ? 0 : 1;
$update['dateno'] = str_replace(' ', '', str_replace('-', '', trim($bj[1])));
$update['doilink'] = "http://doi.org/" . $data['refer_doi'];
$update['cs'] = 1;
}
}
$p_refer_obj->where('p_refer_id',$data['p_refer_id'])->update($update);
$p_refer_obj->where('p_refer_id', $data['p_refer_id'])->update($update);
$p_refer_obj->close();
}
function bekjournal($str){
preg_match("/[0-9]{4}/",$str,$math);
function bekjournal($str)
{
preg_match("/[0-9]{4}/", $str, $math);
$year = $math[0];
$frag[0]=trim(substr($str,0,stripos($str,$year))) ;
$frag[1]=substr($str,stripos($str,$year));
$frag[0] = trim(substr($str, 0, stripos($str, $year)));
$frag[1] = substr($str, stripos($str, $year));
return $frag;
}
function formateJournal($fullname){
function formateJournal($fullname)
{
$obj = Db::name('journal_abbr');
$r = $obj->where('full_name',$fullname)->find();
if($r){
$r = $obj->where('full_name', $fullname)->find();
if ($r) {
return $r['little_name'];
}else{
} else {
return $fullname;
}
}
function prgeAuthor($author){
$a = explode(',',$author);
if(count($a)<7){
return $author.'.';
}else{
return trim($a[0]).', '.trim($a[1]).', '.trim($a[2]).', et al.';
function prgeAuthor($author)
{
$a = explode(',', $author);
if (count($a) < 7) {
return $author . '.';
} else {
return trim($a[0]) . ', ' . trim($a[1]) . ', ' . trim($a[2]) . ', et al.';
}
}
function my_tg_pushmail($data){
$res = sendEmail($data['email'],$data['title'],$data['title'],$data['content'],$data['tmail'],$data['tpassword'],$data['attachmentFile']);
if(isset($res['status'])){
function my_tg_pushmail($data)
{
$res = sendEmail($data['email'], $data['title'], $data['title'], $data['content'], $data['tmail'], $data['tpassword'], $data['attachmentFile']);
if (isset($res['status'])) {
$log_obj = Db::name('email_log');
$insert['article_id'] = $data['article_id'];
$insert['email'] = $data['email'];
$insert['content'] = $data['content'];
$insert['is_success'] = $res['status'];
$insert['attachment'] = $data['attachmentFile']!=''?substr($data['attachmentFile'],strrpos($data['attachmentFile'],'enclosure/')+10):'';
$insert['attachment'] = $data['attachmentFile'] != '' ? substr($data['attachmentFile'], strrpos($data['attachmentFile'], 'enclosure/') + 10) : '';
$insert['ctime'] = time();
$log_obj->insert($insert);
$log_obj->close();
}
}
function getMajorStr($major_id)
{
$major_obj = Db::name('major');
$frag = '';
$major_info = $major_obj->where('major_id', $major_id)->find();
if ($major_info == null) {
return '';
}
if ($major_info['major_level'] == 1) {
return 'Medicine';
} else {
$frag = getMajorStr($major_info['pid']) . ' > ' . $major_info['major_title'];
}
return $frag;
}
function getMajorShu($major)
{
$major_obj = Db::name('major');
if ($major == 0) {
return;
}
$res = $major_obj->where('major_id', $major)->find();
if ($res['pid'] == 1) {
return $res['major_id'];
}
$p = getMajorShu($res['pid']);
return $p . ',' . $res['major_id'];
}
function getReviewerCvs($reviewer_id){
$cvs = Db::name('user_cv')->where('user_id',$reviewer_id)->where('state',0)->select();
return $cvs;
}
/**
* 增加usermsg
*/
function add_usermsg($userid, $content, $url) {
function add_usermsg($userid, $content, $url)
{
$msg_obj = Db::name('user_msg');
$msg_info = $msg_obj->where('user_id', $userid)
->where('url', $url)
->where('state', 0)
->find();
->where('url', $url)
->where('state', 0)
->find();
if ($msg_info) {
return true;
}
@@ -443,15 +493,18 @@ function add_usermsg($userid, $content, $url) {
return $msg_obj->insert($msgdata);
}
function jsonSuccess($data) {
function jsonSuccess($data)
{
return json(['code' => 0, 'msg' => 'success', 'data' => $data]);
}
function jsonError($msg) {
function jsonError($msg)
{
return json(['code' => 1, 'msg' => $msg]);
}
function choiseJabbr($article_id, $jabbr) {
function choiseJabbr($article_id, $jabbr)
{
if ($article_id < 1799 && $jabbr == "Cancer Adv") {
return "TMR Cancer";
}
@@ -468,7 +521,8 @@ function choiseJabbr($article_id, $jabbr) {
function myPost($url, $param = array()) {
function myPost($url, $param = array())
{
if (!is_array($param)) {
@@ -477,8 +531,8 @@ function myPost($url, $param = array()) {
$httph = curl_init($url);
// curl_setopt($httph, CURLOPT_SSL_VERIFYPEER, 0);
// curl_setopt($httph, CURLOPT_SSL_VERIFYHOST, 1);
// curl_setopt($httph, CURLOPT_SSL_VERIFYPEER, 0);
// curl_setopt($httph, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($httph, CURLOPT_RETURNTRANSFER, 1);
@@ -488,8 +542,10 @@ function myPost($url, $param = array()) {
curl_setopt($httph, CURLOPT_POSTFIELDS, $param);
// curl_setopt($httph, CURLOPT_RETURNTRANSFER,0);
// curl_setopt($httph, CURLOPT_HEADER,1);
curl_setopt($httph, CURLOPT_SSL_VERIFYPEER, false);
// curl_setopt($httph, CURLOPT_RETURNTRANSFER,0);
// curl_setopt($httph, CURLOPT_HEADER,1);
$rst = curl_exec($httph);
@@ -498,7 +554,8 @@ function myPost($url, $param = array()) {
return $rst;
}
function myPost1($url, $param = array()) {
function myPost1($url, $param = array())
{
if (!is_array($param)) {
@@ -509,10 +566,10 @@ function myPost1($url, $param = array()) {
$httph = curl_init($url);
curl_setopt($httph, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
));
));
// curl_setopt($httph, CURLOPT_SSL_VERIFYPEER, 0);
// curl_setopt($httph, CURLOPT_SSL_VERIFYHOST, 1);
// curl_setopt($httph, CURLOPT_SSL_VERIFYPEER, 0);
// curl_setopt($httph, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($httph, CURLOPT_RETURNTRANSFER, 1);
@@ -522,8 +579,8 @@ function myPost1($url, $param = array()) {
curl_setopt($httph, CURLOPT_POSTFIELDS, $data);
// curl_setopt($httph, CURLOPT_RETURNTRANSFER,0);
// curl_setopt($httph, CURLOPT_HEADER,1);
// curl_setopt($httph, CURLOPT_RETURNTRANSFER,0);
// curl_setopt($httph, CURLOPT_HEADER,1);
$rst = curl_exec($httph);