This commit is contained in:
zyx0814
2022-01-29 10:44:42 +08:00
Unverified
parent 3d95bf33d6
commit 23a9dea1e9
62 changed files with 5550 additions and 3035 deletions

View File

@@ -245,6 +245,11 @@ class image {
$w = ceil($y_ratio * $this->imginfo['width']);
$h = $this->param['thumbheight'];
}
if($w < 242){
$w = $this->param['thumbwidth'] = 242;
$x_ratio = $this->param['thumbwidth'] / $this->imginfo['width'];
$h = ceil($x_ratio*$this->imginfo['height']);
}
}
return array($x, $y, $w, $h);
}
@@ -356,6 +361,10 @@ class image {
}else{
$width=ceil($height*$or);
if($width < 242){
$width = 242;
$height = ceil($width/$or);
}
}
}else{
@@ -364,6 +373,11 @@ class image {
$width=$owidth;
}else{
$height=ceil($width/$or);
$width = ceil($height*$or);
if($width < 242){
$width = 242;
$height = ceil($width/$or);
}
}
}

View File

@@ -0,0 +1,432 @@
<?php
if (!defined('IN_OAOOA')) {
exit('Access Denied');
}
class table_pichome_collectlist extends dzz_table
{
public function __construct()
{
$this->_table = 'pichome_collectlist';
$this->_pk = 'id';
$this->_pre_cache_key = 'pichome_collectlist';
$this->_cache_ttl = 3600;
parent::__construct();
}
//添加收藏
public function add_collect($data){
$perm = C::t('pichome_collectuser')->get_perm_by_clid($data['clid']);
if($perm < 2){
return array('error'=>'no_perm');
}
if(empty($data['rid'])) return true;
$existsdata = DB::fetch_all("select rid from %t where rid in(%n) and clid = %d and cid = %d",array($this->_table,$data['rid'],$data['clid'],$data['cid']));
$existsrids = [];
foreach($existsdata as $v){
$existsrids[] = $v['rid'];
}
$totalcount = count($data['rid']);
$data['rid'] = array_diff($data['rid'],$existsrids);
if(empty($data['rid'])) return true;
//记录加入收藏个数
$counti = 0;
$namesarr = [];
foreach(DB::fetch_all("select appid,rid,name from %t where rid in(%n)",array('pichome_resources',$data['rid'])) as $v){
$setarr = [
'rid'=>$v['rid'],
'cid'=>$data['cid'],
'clid'=>$data['clid'],
'uid'=>$data['uid'],
'username'=>$data['username'],
'dateline'=>$data['dateline'],
'appid'=>$v['appid'],
];
$namesarr[] = $v['name'];
if(parent::insert($setarr,1)) $counti += 1;
}
if($counti){
$filenamearr = array_slice($namesarr,0,5);
$filename = implode(',',$filenamearr).'等'.$totalcount.'个文件';
//如果收藏有分类增加该分类下文件数
$position = DB::result_first("select name from %t where clid = %d",array('pichome_collect',$data['clid']));
if($data['cid']){
C::t('pichome_collectcat')->add_filenum_by_cid($data['cid'],$counti);
$pathkey = DB::result_first("select pathkey from %t where cid = %d",array('pichome_collectcat',$data['cid']));
$pathkey = str_replace('_','',$pathkey);
$patharr = explode('-',$pathkey);
foreach(DB::fetch_all("select catname from %t where cid in(%n)",array('pichome_collectcat',$patharr)) as $v){
$position .= '/'.$v['catname'];
}
}
C::t('pichome_collect')->add_filenum_by_clid($data['clid'],$counti);
$enventbodydata = ['username'=>getglobal('username'),'filename'=>$filename,'collectname'=>$position,'rids'=> $data['rid']];
$enventdata = [
'eventbody' =>'collectfile' ,
'uid' => getglobal('uid'),
'username' => getglobal('username'),
'bodydata' => json_encode($enventbodydata),
'clid' =>$data['clid'],
'cid' =>($data['cid']) ? $data['cid']:0,
'do' => 'collect_file',
'do_obj' =>$filename,
'dateline'=>TIMESTAMP
];
C::t('pichome_collectevent')->insert($enventdata);
}
$this->update_collect_thumb($data['clid']);
return true;
}
public function delete($id){
if(!is_array($id)) $id = (array)$id;
if(parent::delete($id)){
//删除对应分享
if(!empty($id))DB::delete('pichome_share','filepath in('.dimplode($id).') and stype = 1');
}
return true;
}
//取消收藏
public function cancle_filecollect($lids,$clid,$cid = 0){
$perm = C::t('pichome_collectuser')->get_perm_by_clid($clid);
if($perm < 2){
return array('error'=>'no_perm');
}
if(!is_array($lids)) $lids = (array)$lids;
if(empty($lids)) return true;
$counti = 0;
$rids = [];
foreach(DB::fetch_all("select rid,id,cid,clid from %t where id in(%n)",array($this->_table,$lids)) as $v){
$rids[] = $v['rid'];
if($this->delete($v['id'])){
$counti += 1;
C::t('pichome_collectcat')->add_filenum_by_cid($v['cid'],-1);
C::t('pichome_collect')->add_filenum_by_clid($v['clid'],-1);
}
}
$position = DB::result_first("select name from %t where clid = %d",array('pichome_collect',$clid));
if($cid){
$pathkey = DB::result_first("select pathkey from %t where cid = %d",array('pichome_collectcat',$cid));
$pathkey = str_replace('_','',$pathkey);
$patharr = explode('-',$pathkey);
foreach(DB::fetch_all("select catname from %t where cid in(%n)",array('pichome_collectcat',$patharr)) as $v){
$position .= '/'.$v['catname'];
}
}
$namesarr = [];
foreach(DB::fetch_all("select name from %t where rid in(%n) limit 0,5",array('pichome_resources',$rids)) as $v){
$namesarr[] = $v['name'];
}
$filename = implode(',',$namesarr).'等'.$counti.'个文件';
$enventbodydata = ['username'=>getglobal('username'),'filename'=>$filename,'collectname'=>$position,'rid'=>$rids];
$enventdata = [
'eventbody' =>'canclecollectfile' ,
'uid' => getglobal('uid'),
'username' => getglobal('username'),
'bodydata' => json_encode($enventbodydata),
'clid' =>$clid,
'cid' =>($cid) ? $cid:0,
'do' => 'cancle_collectfile',
'do_obj' =>$filename,
'dateline'=>TIMESTAMP
];
C::t('pichome_collectevent')->insert($enventdata);
$this->update_collect_thumb($clid);
return true;
}
//更新收藏夹缩略图
public function update_collect_thumb($clid){
$first = false;
$collectdata = C::t('pichome_collect')->fetch($clid);
if(!C::t('pichome_collectlist')->fetch($collectdata['lid'])){
$first = true;
}else{
$first = false;
}
$setarr = [];
if($first){
//取得第一张图
$firstdata = DB::fetch_first("select * from %t where clid = %d order by id asc",array($this->_table,$clid));
if($firstdata){
$icondatas = C::t('pichome_resources')->geticondata_by_rid($firstdata['rid']);
$setarr['covert'] = $icondatas['icondata'];
$setarr['lid'] = $firstdata['id'];
}else{
$setarr['covert'] = '';
$setarr['lid'] = 0;
}
}
//取得最新两张图
$i = 2;
$coverdata = DB::fetch_all("select rid,id from %t where clid = %d order by id desc limit 0,2",array($this->_table,$clid));
$count = count($coverdata);
if($count == 0){
$setarr['covert1'] = '';
$setarr['covert2'] = '';
$setarr['lid1'] = 0;
$setarr['lid2'] = 0;
}elseif($count ==1) {
foreach ($coverdata as $v) {
$icondatas = C::t('pichome_resources')->geticondata_by_rid($v['rid']);
$setarr['covert' . $i] = $icondatas['icondata'];
$setarr['lid' . $i] = $v['id'];
$i--;
}
$setarr['covert2'] = '';
$setarr['lid2'] = 0;
}else{
foreach($coverdata as $v){
$icondatas = C::t('pichome_resources')->geticondata_by_rid($v['rid']);
$setarr['covert'.$i] = $icondatas['icondata'];
$setarr['lid'.$i] = $v['id'];
$i--;
}
}
C::t('pichome_collect')->update($clid,$setarr);
return true;
}
//删除收藏夹所有文件
public function delete_by_clid($clid){
return DB::delete($this->_table,array('clid'=>$clid));
}
//移动文件到某收藏
public function move_collectfile($lids,$oclid,$ocid=0){
if(!is_array($lids)) $lids = (array)$lids;
if(empty($lids)) return true;
$total = count($lids);
$cids = [];
$clid = 0;
$counti = 0;
$rids=[];
foreach(DB::fetch_all("select * from %t where id in(%n)",array('pichome_collectlist',$lids)) as $v){
$cids[] = $v['cid'];
$clid = $v['clid'];
//如果收藏位置相同则不做任何处理
if($v['clid'] == $oclid && $v['cid'] == $ocid){
/* if(parent::delete($v['id'])){
//收藏夹文件数和分类数减1
if($v['cid']) C::t('pichome_collectcat')->add_filenum_by_cid($v['cid'],-1);
if($v['clid'])C::t('pichome_collect')->add_filenum_by_clid($v['clid'],-1);
}*/
continue;
}else{
//如果该收藏文件在目标位置已经存在则删除原收藏位置文件
if($id = DB::result_first("select id from %t where rid = %s and clid = %d and cid = %d",
array($this->_table,$v['rird'],$oclid,$ocid))){
$this->delete($id);
C::t('pichome_collect')->add_filenum_by_clid($clid,-1);
if($v['cid'])C::t('pichome_collectcat')->add_filenum_by_cid($v['cid'],-1);
}else{
$setarr = [
'uid'=>getglobal('uid'),
'username'=>getglobal('username'),
'clid'=>$oclid,
'cid'=>$ocid
];
/* echo $ocid;
print_r($v);die;*/
//更新数据
if(parent::update($v['id'],$setarr)){
//如果移动位置不在一个收藏夹
if($v['clid'] != $oclid){
//增加移入收藏夹文件数
C::t('pichome_collect')->add_filenum_by_clid($oclid,1);
if($v['clid']) C::t('pichome_collect')->add_filenum_by_clid($clid,-1);
}
if($v['cid'])C::t('pichome_collectcat')->add_filenum_by_cid($v['cid'],-1);
$counti++;
//增加移入分类文件数
if($ocid)C::t('pichome_collectcat')->add_filenum_by_cid($ocid,1);
}
}
}
$rids[] = $v['rid'];
}
//如果移动文件位置cid为多个则不记入动态
$cids = array_unique($cids);
if(count($cids) == 1) $cid = $cids[0];
else $cid = 0;
$namesarr = [];
foreach(DB::fetch_all("select name from %t where rid in(%n) limit 0,5",array('pichome_resources',$rids)) as $v){
$namesarr[] = $v['name'];
}
$filename = implode(',',$namesarr).'等'.$total.'个文件';
$oposition = DB::result_first("select name from %t where clid = %d",array('pichome_collect',$oclid));
if($ocid){
$pathkey = DB::result_first("select pathkey from %t where cid = %d",array('pichome_collectcat',$ocid));
$pathkey = str_replace('_','',$pathkey);
$patharr = explode('-',$pathkey);
foreach(DB::fetch_all("select catname from %t where cid in(%n)",array('pichome_collectcat',$patharr)) as $v){
$oposition .= '/'.$v['catname'];
}
}
//更新移出收藏文件数
$position = DB::result_first("select name from %t where clid = %d",array('pichome_collect',$clid));
if($cid){
$pathkey = DB::result_first("select pathkey from %t where cid = %d",array('pichome_collectcat',$cid));
$pathkey = str_replace('_','',$pathkey);
$patharr = explode('-',$pathkey);
foreach(DB::fetch_all("select catname from %t where cid in(%n)",array('pichome_collectcat',$patharr)) as $v){
$position .= '/'.$v['catname'];
}
}
//移入动态
$enventbodydata = ['username'=>getglobal('username'),'filename'=>$filename,'collectname'=>$position,'newcolletname'=>$oposition,'rid'=>$rids];
$enventdata = [
'eventbody' =>'movecollectfileto' ,
'uid' => getglobal('uid'),
'username' => getglobal('username'),
'bodydata' => json_encode($enventbodydata),
'clid' =>$oclid,
'cid' =>($ocid) ? $ocid:0,
'do' => 'move_collectfileto',
'do_obj' =>$filename,
'dateline'=>TIMESTAMP
];
C::t('pichome_collectevent')->insert($enventdata);
//更新移入文件收藏缩略图
if($oclid != $clid) $this->update_collect_thumb($oclid);
//移出动态
$enventbodydata = ['username'=>getglobal('username'),'filename'=>$filename,'collectname'=>$position,'newcolletname'=>$oposition,'rid'=>$rids];
$enventdata = [
'eventbody' =>'delcollectfilefrom' ,
'uid' => getglobal('uid'),
'username' => getglobal('username'),
'bodydata' => json_encode($enventbodydata),
'clid' =>$clid,
'cid' =>($cid) ? $cid:0,
'do' => 'del_collectfilefrom',
'do_obj' =>$filename,
'dateline'=>TIMESTAMP
];
C::t('pichome_collectevent')->insert($enventdata);
//更新移出文件收藏缩略图
if($clid && $oclid != $clid) $this->update_collect_thumb($oclid);
return true;
}
//收藏已收藏文件到指定收藏
public function collect_by_lid($lids,$clid,$cid=0){
$perm = C::t('pichome_collectuser')->get_perm_by_clid($clid);
if($perm < 2){
return array('error'=>'no_perm');
}
if(!is_array($lids)) $lids = (array)$lids;
if(empty($lids)) return true;
$rids = [];
foreach(DB::fetch_all("select rid,id from %t where id in(%n)",array($this->_table,$lids)) as $v){
$rids[] = $v['rid'];
}
$existsrids = [];
foreach(DB::fetch_all("select rid from %t where rid in(%n) and clid = %d and cid = %d",array($this->_table,$rids,$clid,$cid)) as $v){
$existsrids[] = $v['rid'];
}
$totalcount = count($rids);
$insertrids = array_diff($rids,$existsrids);
//记录加入收藏个数
$counti = 0;
$namesarr = [];
foreach(DB::fetch_all("select appid,rid,name from %t where rid in(%n)",array('pichome_resources',$insertrids)) as $v){
$setarr = [
'rid'=>$v['rid'],
'cid'=>$cid,
'clid'=>$clid,
'uid'=>getglobal('uid'),
'username'=>getglobal('username'),
'dateline'=>TIMESTAMP,
'appid'=>$v['appid'],
];
$namesarr[] = $v['name'];
if(parent::insert($setarr,1)) $counti += 1;
}
if($counti){
$filenamearr = array_slice($namesarr,0,5);
$filename = implode(',',$filenamearr).'等'.$totalcount.'个文件';
//如果收藏有分类增加该分类下文件数
$position = DB::result_first("select name from %t where clid = %d",array('pichome_collect',$clid));
if($cid){
C::t('pichome_collectcat')->add_filenum_by_cid($cid,$counti);
$pathkey = DB::result_first("select pathkey from %t where cid = %d",array('pichome_collectcat',$cid));
$pathkey = str_replace('_','',$pathkey);
$patharr = explode('-',$pathkey);
foreach(DB::fetch_all("select catname from %t where cid in(%n)",array('pichome_collectcat',$patharr)) as $v){
$position .= '/'.$v['catname'];
}
}
C::t('pichome_collect')->add_filenum_by_clid($clid,$counti);
$enventbodydata = ['username'=>getglobal('username'),'filename'=>$filename,'collectname'=>$position,'rids'=>$rids];
$enventdata = [
'eventbody' =>'collectfile' ,
'uid' => getglobal('uid'),
'username' => getglobal('username'),
'bodydata' => json_encode($enventbodydata),
'clid' =>$clid,
'cid' =>$cid ? $cid:0,
'do' => 'collect_file',
'do_obj' =>$filename,
'dateline'=>TIMESTAMP
];
C::t('pichome_collectevent')->insert($enventdata);
}
$this->update_collect_thumb($clid);
return true;
}
public function delete_by_rids($rids,$uid,$username){
if(!$rids) $rids = (array)$rids;
if(empty($rids)) return true;
$clids = [];
foreach(DB::fetch_all("select * from %t where rid in(%n)",array($this->_table,$rids)) as $v){
$clids[$v['clid']][] = $v['id'];
}
foreach ($clids as $k=>$val){
$clid = $k;
$counti = 0;
$rids = [];
foreach(DB::fetch_all("select rid,id,cid,clid from %t where id in(%n)",array($this->_table,$val)) as $v){
$rids[] = $v['rid'];
if($this->delete($v['id'])){
$counti += 1;
if($v['cid'])C::t('pichome_collectcat')->add_filenum_by_cid($v['cid'],-1);
if($v['clid'])C::t('pichome_collect')->add_filenum_by_clid($v['clid'],-1);
}
}
$position = DB::result_first("select name from %t where clid = %d",array('pichome_collect',$clid));
$namesarr = [];
foreach(DB::fetch_all("select name from %t where rid in(%n) limit 0,5",array('pichome_resources',$rids)) as $v){
$namesarr[] = $v['name'];
}
$filename = implode(',',$namesarr).'等'.$counti.'个文件';
$enventbodydata = ['username'=>getglobal('username'),'filename'=>$filename,'collectname'=>$position,'rid'=>$rids];
$enventdata = [
'eventbody' =>'canclecollectfile' ,
'uid' => $uid,
'username' => $username,
'bodydata' => json_encode($enventbodydata),
'clid' =>$clid,
'cid' =>0,
'do' => 'cancle_collectfile',
'do_obj' =>$filename,
'dateline'=>TIMESTAMP
];
C::t('pichome_collectevent')->insert($enventdata);
$this->update_collect_thumb($clid);
}
return true;
}
}

View File

@@ -29,12 +29,13 @@ class table_pichome_resources extends dzz_table
public function delete_by_appid($appid)
{
$data = C::t('pichome_vapp')->fetch($appid);
//$i = 0;
$rids = [];
foreach (DB::fetch_all("select rid from %t where appid = %s limit 0,1000", array($this->_table, $appid)) as $v) {
foreach (DB::fetch_all("select rid from %t where appid = %s limit 0,100", array($this->_table, $appid)) as $v) {
$rids[] = $v['rid'];
}
if ($rids) $this->delete_by_rid($rids);
if ($rids) $this->delete_by_rid($rids,$data['deluid'],$data['delusername']);
//return $i;
}
@@ -44,7 +45,7 @@ class table_pichome_resources extends dzz_table
return DB::result_first("select * from %t where path = %s", array($this->_table, $path));
}
public function delete_by_rid($rids)
public function delete_by_rid($rids,$uid=0,$username='')
{
if (!is_array($rids)) $rids = (array)$rids;
C::t('pichome_resources_attr')->delete_by_rid($rids);
@@ -55,6 +56,9 @@ class table_pichome_resources extends dzz_table
C::t('pichome_share')->delete_by_rid($rids);
C::t('pichome_ffmpeg_record')->delete($rids);
C::t('pichome_imagickrecord')->delete($rids);
//$deldata = ['rids'=>$rids,'deluid'=>$uid,'delusername'=>$username];
//Hook::listen('pichomedatadeleteafter',$deldata);
return $this->delete($rids);
}
@@ -121,7 +125,40 @@ class table_pichome_resources extends dzz_table
$resourcesdata['realpath'] = $downshare[$resourcesdata['appid']]['path'] . BS . $resourcesdata['path'];
return $resourcesdata;
}
/*public function getdatabyrid($rid){
global $Opentype;
$data = parent::fetch($rid);
$data['fsize'] = formatsize($data['size']);
$data['mtime'] = dgmdate(round($data['mtime'] / 1000), 'Y/m/d H:i');
$data['dateline'] = dgmdate(round($data['dateline'] / 1000), 'Y/m/d H:i');
$data['name'] = str_replace(strrchr($data['name'], "."), "", $data['name']);
$data['btime'] = dgmdate(round($data['btime'] / 1000), 'Y/m/d H:i');
$data['dpath'] = dzzencode($data['rid'], '', 0, 0);
if (in_array($data['ext'], $Opentype['video'])) {
$data['opentype'] = 'video';
} elseif (in_array($data['ext'], $Opentype['text'])) {
$data['opentype'] = 'text';
} elseif (in_array($data['ext'], $Opentype['pdf'])) {
$data['opentype'] = 'pdf';
} elseif (in_array($data['ext'], $Opentype['image'])) {
$data['opentype'] = 'image';
} else {
$data['opentype'] = 'other';
}
$attrdata = C::t('pichome_resources_attr')->fetch($rid);
$data = array_merge($data,$attrdata);
$colordata = C::t('pichome_palette')->fetch_colordata_by_rid($rid);
foreach ($colordata as $cv) {
$colorsarr[] = $cv;
}
$data['color'] = $colorsarr[0];
//array_multisort($datas, 'rid', SORT_ASC, $rids);
foreach (C::t('pichome_resourcestag')->fetch_all_tag_by_rids($rids) as $k => $v) {
$datas[$k]['tags'] = $v;
// $datas[$k]['tags'] = '•'.implode('•',$v);
}
}*/
public function fetch_by_rid($rid)
{
global $Opentype;
@@ -130,6 +167,7 @@ class table_pichome_resources extends dzz_table
//获取所有库分享和下载权限
$downshare = C::t('pichome_vapp')->fetch_all_sharedownlod();
$attrdata = C::t('pichome_resources_attr')->fetch($rid);
if($attrdata['desc']) $attrdata['desc'] = strip_tags($attrdata['desc']);
$resourcesdata = array_merge($resourcesdata, $attrdata);
$resourcesdata['colors'] = C::t('pichome_palette')->fetch_colordata_by_rid($rid);
$resourcesdata['ext'] = strtolower($resourcesdata['ext']);
@@ -234,7 +272,7 @@ class table_pichome_resources extends dzz_table
$resourcesdata['foldernames'] = C::t('pichome_folderresources')->get_foldername_by_rid($rid);
$resourcesdata['tag'] = C::t('pichome_resourcestag')->fetch_tag_by_rid($rid);
$resourcesdata['dpath'] = dzzencode($rid, '', 0, 0);
//print_r($resourcesdata);die;
return $resourcesdata;
}
@@ -306,6 +344,11 @@ class table_pichome_resources extends dzz_table
$v['height'] = 128;
}
}
$thumbwidth = getglobal('config/pichomethumbwidth') ? getglobal('config/pichomethumbwidth') : 900;
$thumbheight = getglobal('config/pichomethumbheight') ? getglobal('config/pichomethumbheight') : 900;
$thumsizearr = $this->getImageThumbsize($v['width'],$v['height'],$thumbwidth,$thumbheight);
$v['thumbwidth'] = $thumsizearr[0];
$v['thumbheight'] = $thumsizearr[1];
//文件真实地址
if ($downshare[$v['appid']]['iswebsitefile']) {
$originalimg = str_replace(DZZ_ROOT, '', $downshare[$v['appid']]['path'] . BS . $v['path']);
@@ -316,13 +359,50 @@ class table_pichome_resources extends dzz_table
$v['realpath'] = getglobal('siteurl') . 'index.php?mod=io&op=getImg&path=' . dzzencode($originalimg, '', 0, 0);
}
unset($v['path']);
$returndata[] = $v;
}
return $returndata;
}
public function getImageThumbsize($owidth,$oheight,$width,$height){
if($owidth>$width || $oheight>$height){
$or=$owidth/$oheight;
$r=$width/$height;
if($r>$or){
if($oheight<$height){
$height=$oheight;
$width=$owidth;
}else{
$width=ceil($height*$or);
if($width < 242){
$width = 242;
$height = ceil($width/$or);
}
}
}else{
if($owidth<$width){
$height=$oheight;
$width=$owidth;
}else{
$height=ceil($width/$or);
$width = ceil($height*$or);
if($width < 242){
$width = 242;
$height = ceil($width/$or);
}
}
}
}else{
$width=$owidth;
$height=$oheight;
}
//Return the results
return array($width,$height);
}
public function geticondata_by_rid($rid)
{
$resourcesdata = DB::fetch_first("select r.rid,r.appid,r.hasthumb,r.ext,r.type,ra.path as fpath,

View File

@@ -11,8 +11,8 @@ if(!defined('IN_OAOOA')) {
}
if(!defined('CORE_VERSION')) {
define('CORE_VERSION', 'beta3.1');
define('CORE_VERSION', 'beta3.2');
define('CORE_VERSION_LEVEL', 'Pichome');
define('CORE_RELEASE', '20211220');
define('CORE_FIXBUG' , '03100000');
define('CORE_RELEASE', '20220128');
define('CORE_FIXBUG' , '03200000');
}