From 46cbba87f16f5a7f228312800abda68a1209c84c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=83=A1?= <3203164629@qq.com> Date: Mon, 29 Jan 2024 18:21:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=87=B3v1.87.3=EF=BC=8C?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=86=85=E5=AE=B9=E5=9C=A8Dzzoffice=E7=AC=94?= =?UTF-8?q?=E8=AE=B0=E4=B8=AD=E6=9F=A5=E7=9C=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/class/table/table_admincp_session.php | 48 + core/class/table/table_app_market.php | 213 + core/class/table/table_app_open.php | 117 + core/class/table/table_app_open_default.php | 43 + core/class/table/table_app_organization.php | 91 + core/class/table/table_app_pic.php | 73 + core/class/table/table_app_relative.php | 61 + core/class/table/table_app_tag.php | 95 + core/class/table/table_app_user.php | 65 + core/class/table/table_attachment.php | 161 + core/class/table/table_cache.php | 26 + core/class/table/table_collect.php | 35 + core/class/table/table_comment.php | 172 + core/class/table/table_comment_at.php | 55 + core/class/table/table_comment_attach.php | 180 + core/class/table/table_connect.php | 77 + core/class/table/table_connect_disk.php | 82 + core/class/table/table_connect_ftp.php | 82 + core/class/table/table_connect_onedrive.php | 83 + core/class/table/table_connect_pan.php | 83 + core/class/table/table_connect_storage.php | 84 + core/class/table/table_cron.php | 39 + core/class/table/table_district.php | 41 + core/class/table/table_document.php | 127 + core/class/table/table_document_event.php | 54 + core/class/table/table_document_reversion.php | 199 + core/class/table/table_failedlogin.php | 38 + core/class/table/table_folder.php | 600 +++ core/class/table/table_folder_attr.php | 129 + core/class/table/table_folder_default.php | 39 + core/class/table/table_folder_flag.php | 32 + .../table/table_folder_flag_formlist.php | 48 + core/class/table/table_folder_sub.php | 52 + core/class/table/table_form_setting.php | 131 + core/class/table/table_hooks.php | 86 + core/class/table/table_icon.php | 64 + core/class/table/table_iconview.php | 28 + core/class/table/table_imagetype.php | 33 + core/class/table/table_local_router.php | 102 + core/class/table/table_local_storage.php | 119 + core/class/table/table_mailcron.php | 45 + core/class/table/table_mailqueue.php | 38 + core/class/table/table_notification.php | 91 + core/class/table/table_onlinetime.php | 37 + core/class/table/table_organization.php | 1065 +++++ core/class/table/table_organization_admin.php | 208 + core/class/table/table_organization_job.php | 54 + core/class/table/table_organization_upjob.php | 45 + core/class/table/table_organization_user.php | 428 ++ core/class/table/table_process.php | 30 + core/class/table/table_resources.php | 1058 +++++ core/class/table/table_resources_attr.php | 123 + core/class/table/table_resources_cat.php | 83 + .../class/table/table_resources_clipboard.php | 113 + core/class/table/table_resources_collect.php | 138 + core/class/table/table_resources_event.php | 469 +++ core/class/table/table_resources_path.php | 247 ++ .../class/table/table_resources_permgroup.php | 72 + core/class/table/table_resources_recyle.php | 332 ++ core/class/table/table_resources_statis.php | 149 + core/class/table/table_resources_tag.php | 180 + core/class/table/table_resources_version.php | 466 +++ core/class/table/table_session.php | 128 + core/class/table/table_setting.php | 79 + core/class/table/table_shares.php | 288 ++ core/class/table/table_shorturl.php | 66 + core/class/table/table_smiley.php | 104 + core/class/table/table_syscache.php | 115 + core/class/table/table_tag.php | 70 + core/class/table/table_thame.php | 25 + core/class/table/table_user.php | 582 +++ core/class/table/table_user_field.php | 25 + core/class/table/table_user_profile.php | 206 + .../table/table_user_profile_setting.php | 69 + core/class/table/table_user_qqconnect.php | 35 + core/class/table/table_user_salf.php | 47 + core/class/table/table_user_sdk.php | 29 + core/class/table/table_user_setting.php | 135 + core/class/table/table_user_status.php | 109 + core/class/table/table_user_verify.php | 85 + core/class/table/table_user_verify_info.php | 112 + core/class/table/table_user_wechat.php | 27 + core/class/table/table_usergroup.php | 138 + core/class/table/table_usergroup_field.php | 30 + core/class/table/table_vote.php | 62 + core/class/table/table_vote_item.php | 119 + core/class/table/table_vote_item_count.php | 37 + core/class/table/table_wx_app.php | 25 + core/cron/cron_cache_cleanup_week.php | 50 + .../cron_clean_copys0_attachment_by_month.php | 21 + core/cron/cron_clean_notification_month.php | 19 + core/cron/cron_database_backup.php | 227 ++ core/cron/cron_fragment_cleanup_day.php | 35 + core/cron/cron_getAtoken_by_Rtoken_week.php | 34 + core/cron/cron_imgcache_cleanup_week.php | 38 + core/cron/cron_movetospace_attachment.php | 22 + core/function/cache/cache_fields_optional.php | 33 + core/function/cache/cache_fields_register.php | 26 + core/function/cache/cache_fields_required.php | 34 + core/function/cache/cache_organization.php | 22 + core/function/cache/cache_profilesetting.php | 13 + core/function/cache/cache_setting.php | 135 + core/function/cache/cache_smileycodes.php | 21 + core/function/cache/cache_smileytypes.php | 20 + core/function/cache/cache_smilies.php | 20 + core/function/cache/cache_smilies_js.php | 57 + core/function/cache/cache_usergroups.php | 44 + core/function/cache/cache_userstats.php | 16 + core/function/function_cache.php | 162 + core/function/function_code.php | 527 +++ core/function/function_core.php | 3571 +++++++++++++++++ core/function/function_filesock.php | 183 + core/function/function_mail.php | 306 ++ core/function/function_message.php | 204 + core/function/function_misc.php | 257 ++ core/function/function_organization.php | 281 ++ core/function/function_seccode.php | 59 + core/function/function_security.php | 137 + core/language/en-US/lang.php | 1272 ++++++ core/language/zh-cn/lang.php | 1299 ++++++ core/template/default/common/about.htm | 43 + core/template/default/common/adminlogin.htm | 160 + .../template/default/common/adminlogineer.htm | 22 + core/template/default/common/beijing.htm | 16 + .../template/default/common/commer_header.htm | 54 + core/template/default/common/copyright.htm | 4 + core/template/default/common/footer.htm | 140 + core/template/default/common/footer_ajax.htm | 1 + .../template/default/common/footer_reload.htm | 2 + .../template/default/common/footer_simple.htm | 147 + .../template/default/common/footer_system.htm | 122 + core/template/default/common/header_ajax.htm | 10 + .../template/default/common/header_common.htm | 31 + core/template/default/common/header_left.htm | 4 + .../template/default/common/header_reload.htm | 16 + core/template/default/common/header_right.htm | 150 + .../template/default/common/header_simple.htm | 39 + .../default/common/header_simple_end.htm | 17 + .../default/common/header_simple_start.htm | 40 + core/template/default/common/safechk.htm | 177 + core/template/default/common/seccheck.htm | 32 + core/template/default/common/showmessage.htm | 114 + core/template/default/common/showtips.htm | 4 + core/template/default/common/wx_ajax.htm | 139 + core/template/default/common/wx_appinfo.htm | 216 + core/template/default/common/wx_menu.htm | 503 +++ core/template/default/common/wx_mpinfo.htm | 147 + 147 files changed, 23600 insertions(+) create mode 100644 core/class/table/table_admincp_session.php create mode 100644 core/class/table/table_app_market.php create mode 100644 core/class/table/table_app_open.php create mode 100644 core/class/table/table_app_open_default.php create mode 100644 core/class/table/table_app_organization.php create mode 100644 core/class/table/table_app_pic.php create mode 100644 core/class/table/table_app_relative.php create mode 100644 core/class/table/table_app_tag.php create mode 100644 core/class/table/table_app_user.php create mode 100644 core/class/table/table_attachment.php create mode 100644 core/class/table/table_cache.php create mode 100644 core/class/table/table_collect.php create mode 100644 core/class/table/table_comment.php create mode 100644 core/class/table/table_comment_at.php create mode 100644 core/class/table/table_comment_attach.php create mode 100644 core/class/table/table_connect.php create mode 100644 core/class/table/table_connect_disk.php create mode 100644 core/class/table/table_connect_ftp.php create mode 100644 core/class/table/table_connect_onedrive.php create mode 100644 core/class/table/table_connect_pan.php create mode 100644 core/class/table/table_connect_storage.php create mode 100644 core/class/table/table_cron.php create mode 100644 core/class/table/table_district.php create mode 100644 core/class/table/table_document.php create mode 100644 core/class/table/table_document_event.php create mode 100644 core/class/table/table_document_reversion.php create mode 100644 core/class/table/table_failedlogin.php create mode 100644 core/class/table/table_folder.php create mode 100644 core/class/table/table_folder_attr.php create mode 100644 core/class/table/table_folder_default.php create mode 100644 core/class/table/table_folder_flag.php create mode 100644 core/class/table/table_folder_flag_formlist.php create mode 100644 core/class/table/table_folder_sub.php create mode 100644 core/class/table/table_form_setting.php create mode 100644 core/class/table/table_hooks.php create mode 100644 core/class/table/table_icon.php create mode 100644 core/class/table/table_iconview.php create mode 100644 core/class/table/table_imagetype.php create mode 100644 core/class/table/table_local_router.php create mode 100644 core/class/table/table_local_storage.php create mode 100644 core/class/table/table_mailcron.php create mode 100644 core/class/table/table_mailqueue.php create mode 100644 core/class/table/table_notification.php create mode 100644 core/class/table/table_onlinetime.php create mode 100644 core/class/table/table_organization.php create mode 100644 core/class/table/table_organization_admin.php create mode 100644 core/class/table/table_organization_job.php create mode 100644 core/class/table/table_organization_upjob.php create mode 100644 core/class/table/table_organization_user.php create mode 100644 core/class/table/table_process.php create mode 100644 core/class/table/table_resources.php create mode 100644 core/class/table/table_resources_attr.php create mode 100644 core/class/table/table_resources_cat.php create mode 100644 core/class/table/table_resources_clipboard.php create mode 100644 core/class/table/table_resources_collect.php create mode 100644 core/class/table/table_resources_event.php create mode 100644 core/class/table/table_resources_path.php create mode 100644 core/class/table/table_resources_permgroup.php create mode 100644 core/class/table/table_resources_recyle.php create mode 100644 core/class/table/table_resources_statis.php create mode 100644 core/class/table/table_resources_tag.php create mode 100644 core/class/table/table_resources_version.php create mode 100644 core/class/table/table_session.php create mode 100644 core/class/table/table_setting.php create mode 100644 core/class/table/table_shares.php create mode 100644 core/class/table/table_shorturl.php create mode 100644 core/class/table/table_smiley.php create mode 100644 core/class/table/table_syscache.php create mode 100644 core/class/table/table_tag.php create mode 100644 core/class/table/table_thame.php create mode 100644 core/class/table/table_user.php create mode 100644 core/class/table/table_user_field.php create mode 100644 core/class/table/table_user_profile.php create mode 100644 core/class/table/table_user_profile_setting.php create mode 100644 core/class/table/table_user_qqconnect.php create mode 100644 core/class/table/table_user_salf.php create mode 100644 core/class/table/table_user_sdk.php create mode 100644 core/class/table/table_user_setting.php create mode 100644 core/class/table/table_user_status.php create mode 100644 core/class/table/table_user_verify.php create mode 100644 core/class/table/table_user_verify_info.php create mode 100644 core/class/table/table_user_wechat.php create mode 100644 core/class/table/table_usergroup.php create mode 100644 core/class/table/table_usergroup_field.php create mode 100644 core/class/table/table_vote.php create mode 100644 core/class/table/table_vote_item.php create mode 100644 core/class/table/table_vote_item_count.php create mode 100644 core/class/table/table_wx_app.php create mode 100644 core/cron/cron_cache_cleanup_week.php create mode 100644 core/cron/cron_clean_copys0_attachment_by_month.php create mode 100644 core/cron/cron_clean_notification_month.php create mode 100644 core/cron/cron_database_backup.php create mode 100644 core/cron/cron_fragment_cleanup_day.php create mode 100644 core/cron/cron_getAtoken_by_Rtoken_week.php create mode 100644 core/cron/cron_imgcache_cleanup_week.php create mode 100644 core/cron/cron_movetospace_attachment.php create mode 100644 core/function/cache/cache_fields_optional.php create mode 100644 core/function/cache/cache_fields_register.php create mode 100644 core/function/cache/cache_fields_required.php create mode 100644 core/function/cache/cache_organization.php create mode 100644 core/function/cache/cache_profilesetting.php create mode 100644 core/function/cache/cache_setting.php create mode 100644 core/function/cache/cache_smileycodes.php create mode 100644 core/function/cache/cache_smileytypes.php create mode 100644 core/function/cache/cache_smilies.php create mode 100644 core/function/cache/cache_smilies_js.php create mode 100644 core/function/cache/cache_usergroups.php create mode 100644 core/function/cache/cache_userstats.php create mode 100644 core/function/function_cache.php create mode 100644 core/function/function_code.php create mode 100644 core/function/function_core.php create mode 100644 core/function/function_filesock.php create mode 100644 core/function/function_mail.php create mode 100644 core/function/function_message.php create mode 100644 core/function/function_misc.php create mode 100644 core/function/function_organization.php create mode 100644 core/function/function_seccode.php create mode 100644 core/function/function_security.php create mode 100644 core/language/en-US/lang.php create mode 100644 core/language/zh-cn/lang.php create mode 100644 core/template/default/common/about.htm create mode 100644 core/template/default/common/adminlogin.htm create mode 100644 core/template/default/common/adminlogineer.htm create mode 100644 core/template/default/common/beijing.htm create mode 100644 core/template/default/common/commer_header.htm create mode 100644 core/template/default/common/copyright.htm create mode 100644 core/template/default/common/footer.htm create mode 100644 core/template/default/common/footer_ajax.htm create mode 100644 core/template/default/common/footer_reload.htm create mode 100644 core/template/default/common/footer_simple.htm create mode 100644 core/template/default/common/footer_system.htm create mode 100644 core/template/default/common/header_ajax.htm create mode 100644 core/template/default/common/header_common.htm create mode 100644 core/template/default/common/header_left.htm create mode 100644 core/template/default/common/header_reload.htm create mode 100644 core/template/default/common/header_right.htm create mode 100644 core/template/default/common/header_simple.htm create mode 100644 core/template/default/common/header_simple_end.htm create mode 100644 core/template/default/common/header_simple_start.htm create mode 100644 core/template/default/common/safechk.htm create mode 100644 core/template/default/common/seccheck.htm create mode 100644 core/template/default/common/showmessage.htm create mode 100644 core/template/default/common/showtips.htm create mode 100644 core/template/default/common/wx_ajax.htm create mode 100644 core/template/default/common/wx_appinfo.htm create mode 100644 core/template/default/common/wx_menu.htm create mode 100644 core/template/default/common/wx_mpinfo.htm diff --git a/core/class/table/table_admincp_session.php b/core/class/table/table_admincp_session.php new file mode 100644 index 0000000..aa932ec --- /dev/null +++ b/core/class/table/table_admincp_session.php @@ -0,0 +1,48 @@ +_table = 'admincp_session'; + $this->_pk = 'uid'; + + parent::__construct(); + } + + public function fetch($uid, $panel) { + $sql = 'SELECT * FROM %t WHERE uid=%d AND panel=%d'; + return DB::fetch_first($sql, array($this->_table, $uid, $panel)); + } + + public function fetch_all_by_panel($panel) { + return DB::fetch_all('SELECT * FROM %t WHERE panel=%d', array($this->_table, $panel), 'uid'); + } + + public function delete($uid, $panel, $ttl = 3600) { + + + $sql = 'DELETE FROM %t WHERE (uid=%d AND panel=%d) OR dateline<%d'; + DB::query($sql, array($this->_table, $uid, $panel, TIMESTAMP-intval($ttl))); + + } + + public function update($uid, $panel, $data) { + if(!empty($data) && is_array($data)) { + DB::update($this->_table, $data, array('uid'=>$uid, 'panel'=>$panel)); + } + } + +} + +?> diff --git a/core/class/table/table_app_market.php b/core/class/table/table_app_market.php new file mode 100644 index 0000000..f47a039 --- /dev/null +++ b/core/class/table/table_app_market.php @@ -0,0 +1,213 @@ +_table = 'app_market'; + $this->_pk = 'appid'; + $this->_pre_cache_key = 'app_market_'; + $this->_cache_ttl = 60*60; + + parent::__construct(); + } + public function update($appid,$setarr){ + if(($ret=parent::update($appid,$setarr)) && isset($setarr['available'])){ + //如果是启用或关闭时,更新钩子表的status字段 + C::t('hooks')->update_by_appid($appid,array('status'=>intval($setarr['available']))); + } + return $ret; + } + + public function fetch_by_appid($appid,$havecount=false){ //返回一条数据同时加载统计表数据 + global $_G; + $appid = intval($appid); + if(!$data=parent::fetch($appid)) return array(); + if($data['appico']!='dzz/images/default/icodefault.png' && !preg_match("/^(http|ftp|https|mms)\:\/\/(.+?)/i", $data['appico'])){ + $data['appico']=$_G['setting']['attachurl'].$data['appico']; + } + $data['fileext']=$data['fileext']?explode(',',$data['fileext']):array(); + $data['icon']=$data['appico']; + $data['title']=$data['appname']; + $data['url']=replace_canshu($data['appurl']); + if($havecount){ + $data['viewnum']=intval($count['viewnum']); + $data['replynum']=intval($count['replynum']); + $data['downnum']=intval($count['downnum']); + $data['star']=intval($count['star']); + $data['starnum']=intval($count['starnum']); + } + return $data; + } + public function fetch_all_by_appid($appids,$havecount=false){ //返回数据同时加载统计表数据 + global $_G; + if(!$appids) return false; + if(!is_array($appids)){ + $appids=array($appids); + } + $return=array(); + foreach($appids as $appid){ + $appid = intval($appid); + if(!$data=self::fetch($appid)) continue; + if($data['appico']!='dzz/images/default/icodefault.png' && !preg_match("/^(http|ftp|https|mms)\:\/\/(.+?)/i", $data['appico'])){ + $data['appico']=$_G['setting']['attachurl'].$data['appico']; + } + $data['fileext']=$data['fileext']?explode(',',$data['fileext']):array(); + $data['icon']=$data['appico']; + $data['title']=$data['appname']; + $data['url']=replace_canshu($data['appurl']); + if($havecount){ + $data['viewnum']=intval($count['viewnum']); + $data['replynum']=intval($count['replynum']); + $data['downnum']=intval($count['downnum']); + $data['star']=intval($count['star']); + $data['starnum']=intval($count['starnum']); + } + $return[$appid]=$data; + } + return $return; + } + public function delete_by_appid($appids){ //删除应用 + global $_G; + if(!is_array($appids)) $appids=array(intval($appids)); + + $data=DB::fetch_all("SELECT * FROM %t WHERE appid IN(%n)",array($this->_table,$appids)); + foreach($data as $value){ + + if(strpos($value['appico'],'appico')===0){//删除应用图标 + @unlink($_G['setting']['attachdir'].$value['appico']); + } + C::t('app_pic')->delete_by_appid($value['appid']);//删除介绍图片 + C::t('app_open')->delete_by_appid($value['appid']);//删除打开方式; + C::t('app_relative')->delete_by_appid($value['appid']);//删除标签 + C::t('app_user')->delete_by_appid($value['appid']); //删除用户默认打开方式 + C::t('app_organization')->delete_by_appid($value['appid']);//删除部门应用 + C::t('hooks')->delete_by_appid($value['appid']);//删除相关钩子 + } + $this->delete($appids); + return true; + } + /*public function fetch_all_by_tagid($classid,$count=false,$force=false){ + if($force || ($data = $this->fetch_cache(intval($classid),'app_market_class_') === false)) { + $data=DB::fetch_all("select * from %t where classid= %d ",array($this->_table,$classid)); + if(!empty($data)) $this->store_cache(intval($classid), $data, 3600,'app_market_class_'); + } + return $count?count($data):$data; + }*/ + + public function get_appid_by_appurl($appurl){ + return DB::fetch_all("select appid from %t where appurl=%s",array($this->_table,$appurl)); + + } + public function fetch_all_by_notdelete($uid=0){ //取得所有默认不能删除的应用 + if($uid && $space=getuserbyuid($uid)){ + if($space['groupid']==1){//系统管理员 + $l=" `group` = '1'"; + if($notappids=C::t('app_organization')->fetch_notin_appids_by_uid($uid)){ + $l.=" and appid NOT IN (".dimplode($notappids).") "; + } + $sql="`position`>0 and (`group`='0' OR `group`=2 OR `group`=3 OR (".$l.")) "; + }elseif($space['groupid']==2){ + $l=" (`group` = '1')"; + if($notappids=C::t('app_organization')->fetch_notin_appids_by_uid($uid)){ + $l.=" and appid NOT IN (".dimplode($notappids).") "; + } + $sql=" `position`>0 and (`group` = '2' OR `group`='0' or (".$l."))"; + }else{ //普通成员 + //属于普通用户应用但不属于特定部门的应用 + $l=" (`group` = '1')"; + if($notappids=C::t('app_organization')->fetch_notin_appids_by_uid($uid)){ + $l.=" and appid NOT IN (".dimplode($notappids).") "; + } + $sql="`position`>0 and (`group`='0' or (".$l."))"; + } + }else{ //游客 + $sql="`position`>0 and (`group`='-1' or `group`='0')"; + } + return DB::fetch_all("select * from %t where $sql and notdelete>0 and available>0 order by disp ",array($this->_table),'appid'); + } + public function fetch_all_by_default($uid=0){ //取得所有默认的应用 + if($uid && $space=getuserbyuid($uid)){ + if($space['groupid']==1){//系统管理员 + $l="`group` = '1'"; + if($notappids=C::t('app_organization')->fetch_notin_appids_by_uid($uid)){ + $l.=" and appid NOT IN (".dimplode($notappids).") "; + } + $sql="`position`>0 and (`group`='0' OR `group`='2' OR `group`='3' OR (".$l."))"; + }elseif($space['groupid']==2){ + $l=" (`group` = '1')"; + if($notappids=C::t('app_organization')->fetch_notin_appids_by_uid($uid)){ + $l.=" and appid NOT IN (".dimplode($notappids).") "; + } + $sql=" `position`>0 and (`group` = '2' OR `group`='0' or (".$l."))"; + }else{ //普通成员 + //属于普通用户应用但不属于特定部门的应用 + $l=" (`group` = '1')"; + if($notappids=C::t('app_organization')->fetch_notin_appids_by_uid($uid)){ + $l.=" and appid NOT IN (".dimplode($notappids).") "; + } + $sql="`position`>0 and (`group`='0' or (".$l."))"; + } + }else{ //游客 + $sql="`position`>0 and (`group`='-1' or `group`='0')"; + } + //exit($sql); + return DB::fetch_all("select * from %t where $sql and available>0 order by disp ",array($this->_table),'appid'); + } + public function fetch_appid_by_mod($mod,$match=0){//$match==1表示全匹配,默认模糊匹配 + $sql=''; + $param=array($this->_table); + if(!$match){ + $sql=" appurl LIKE %s"; + $param[]='%'.$mod.'%'; + }else{ + $sql=" appurl = %s"; + $param[]=$mod; + } + return DB::result_first("select appid from %t where $sql ",$param); + } + public function fetch_appid($mod){ + $sql=''; + $param=array($this->_table); + $sql=" identifier = %s"; + $param[]=$mod; + return DB::result_first("select appid from %t where $sql ",$param); + } + public function fetch_by_identifier($identifier,$app_path='dzz'){ + return DB::fetch_first("select * from %t where app_path=%s and identifier=%s ",array($this->_table,$app_path,$identifier)); + } + public function fetch_by_mod(){ + return DB::fetch_first("select * from %t where app_path=%s and identifier=%s ",array($this->_table,CURSCRIPT,CURMODULE)); + } + public function fetch_all_identifier($available=0){ + $data=array(); + $sql="identifier!=''"; + if($available){ + $sql.=" and `available`>0"; + } + foreach(DB::fetch_all("select appid,identifier,app_path from %t where %i ",array($this->_table,$sql)) as $value){ + $data[$value['appid']]=$value; + } + return $data; + } + public function fetch_all_by_appurl($appurl,$identifier){ + + return DB::fetch_all("select * from %t where appurl=%s and identifier=%s",array($this->_table,$appurl,$identifier)); + } + public function fetch_appico_by_appid($appid){ + $appid = intval($appid); + return DB::result_first("select appico from %t where appid = %d",array($this->_table,$appid)); + } + +} diff --git a/core/class/table/table_app_open.php b/core/class/table/table_app_open.php new file mode 100644 index 0000000..7b3ad67 --- /dev/null +++ b/core/class/table/table_app_open.php @@ -0,0 +1,117 @@ +_table = 'app_open'; + $this->_pk = 'extid'; + $this->_pre_cache_key = 'app_open_'; + $this->_cache_ttl =0; + parent::__construct(); + } + public function setDefault($extid){ + $data=self::fetch($extid); + DB::update($this->_table,array('isdefault'=>0),"ext='{$data[ext]}'"); + $this->clear_cache('ext_all'); + $this->clear_cache('all'); + return self::update($extid,array('isdefault'=>1)); + } + public function setOrders($extid){ + foreach($extid as $k=>$v ){ + $result = self::update($v,array('disp'=>$k)); + } + $this->clear_cache('ext_all'); + $this->clear_cache('all'); + return true; + } + public function delete_by_appid($appid){ + if(!$appid) return false; + $query=DB::query("SELECT * FROM %t WHERE appid=%d ",array($this->_table,$appid)); + while($value=DB::fetch($query)){ + if($value['extid']){ + $result=C::t('app_open_default')->delete_by_extid($value['extid']); + } + } + $this->clear_cache('ext_all'); + $this->clear_cache('all'); + return DB::delete($this->_table," appid='{$appid}'"); + } + public function insert_by_exts($appid,$exts){ + if(!$appid) return false; + if(!is_array($exts)) $exts=$exts?explode(',',$exts):array(); + //删除原来的ext + $oexts=array(); + $delids=array(); + $oextarr=DB::fetch_all("select * from ".DB::table('app_open')." where appid='{$appid}'"); + foreach($oextarr as $value){ + $oexts[]=$value['ext']; + if(!in_array($value['ext'],$exts)) $delids[]=$value['extid']; + } + if($delids) { + self::delete($delids); + } + foreach($exts as $ext){ + if($ext && !in_array($ext,$oexts)) parent::insert(array('ext'=>$ext,'appid'=>$appid)); + } + $this->clear_cache('ext_all'); + $this->clear_cache('all'); + return true; + } + + public function fetch_all_ext(){ + $data = array(); + if(($data = $this->fetch_cache('all')) === false) { + $data = array(); + $query=DB::query("SELECT * FROM %t WHERE 1 ",array($this->_table)); + while($value=DB::fetch($query)){ + if($value['appid']){ + if($app=C::t('app_market')->fetch_by_appid($value['appid'],false)){ + if($app['available']<1) continue; + if(!$value['icon']) $value['icon']=$app['appico']; + if(!$value['name']) $value['name']=$app['appname']; + if(!$value['url']) $value['url']=$app['appurl']; + if(!$value['nodup']) $value['nodup']=$app['nodup']; + if(!$value['feature']) $value['feature']=$app['feature']; + }else{ + continue; + } + } + $value['url']=replace_canshu($value['url']); + $data[$value['extid']]=$value; + } + if(!empty($data)) $this->store_cache('all', $data); + } + return $data; + } + public function fetch_all_orderby_ext($uid,$ext_all=array()){ + $data = array(); + if($config = C::t('user_field')->fetch($uid)){ + if($config['applist']){ + $appids=explode(',',$config['applist']); + }else{ + $appids=array(); + } + } + if(!$ext_all) $ext_all=self::fetch_all_ext(); + foreach($ext_all as $value){ + if($value['appid'] && !in_array($value['appid'],$appids)){ + continue; + } + $data[$value['ext']][]=$value['extid']; + } + return $data; + + } + +} +?> diff --git a/core/class/table/table_app_open_default.php b/core/class/table/table_app_open_default.php new file mode 100644 index 0000000..ab518f0 --- /dev/null +++ b/core/class/table/table_app_open_default.php @@ -0,0 +1,43 @@ +_table = 'app_open_default'; + $this->_pk = ''; + //$this->_pre_cache_key = 'app_open_'; + //$this->_cache_ttl = 0; + parent::__construct(); + } + public function delete_by_extid($extid){ + return DB::delete($this->_table," extid='{$extid}'"); + } + + public function insert_default_by_uid($uid,$extid,$ext){ + DB::insert($this->_table,array('uid'=>$uid,'ext'=>$ext,'extid'=>$extid,'dateline'=>TIMESTAMP),0,1); + return true; + } + public function fetch_all_by_uid($uid){ + $data=array(); + $query=DB::query("SELECT ext,extid FROM %t WHERE uid= %d ",array($this->_table,$uid)); + while($value=DB::fetch($query)){ + $data[$value['ext']]=$value['extid']; + } + return $data; + } + +} + +?> diff --git a/core/class/table/table_app_organization.php b/core/class/table/table_app_organization.php new file mode 100644 index 0000000..7bcd6ce --- /dev/null +++ b/core/class/table/table_app_organization.php @@ -0,0 +1,91 @@ +_table = 'app_organization'; + $this->_pk = ''; + parent::__construct(); + } + public function insert($appid, $orgid) { + return DB::insert($this->_table, array("orgid"=>$orgid,'appid'=>$appid,'dateline'=>TIMESTAMP),1,1); + } + public function replace_orgids_by_appid($appid,$orgids){ + $Oorgids=self::fetch_orgids_by_appid($appid); + if(!is_array($orgids)) $orgids=array($orgids); + $insertids=array_diff($orgids,$Oorgids); + $delids=array_diff($Oorgids,$orgids); + if($delids) DB::delete($this->_table,"appid='{$appid}' and orgid IN (".dimplode($delids).")"); + foreach($insertids as $orgid){ + if($orgid>0) self::insert($appid,$orgid); + } + return true; + } + public function delete_by_appid($appid) { + return DB::delete($this->_table, "appid='{$appid}'"); + } + public function delete_by_orgid($orgids) { + if(!$orgids) return; + if(!is_array($orgids)) $orgids=array($orgids); + return DB::delete($this->_table, "orgid IN (".dimplode($orgids).")"); + } + public function fetch_appids_by_orgid($orgids,$sub=false){ + $appids=array(); + $orgids=(array)$orgids; + if($sub){ + + foreach(DB::fetch_all("select * from %t where 1",array($this->_table)) as $value){ + if(($porgids= C::t('organization')->fetch_parent_by_orgid($value['orgid'],true)) && array_intersect($porgids,$orgids)){ + $appids[]=$value['appid']; + } + } + }else{ + $query=DB::query("select appid from %t where orgid IN(%n)",array($this->_table,$orgids)); + while($value=DB::fetch($query)){ + $appids[]=$value['appid']; + } + } + return $appids; + } + public function fetch_notin_appids_by_uid($uid){ + $paichu_appids=$orgids=array(); + foreach(C::t('organization_user')->fetch_orgids_by_uid($uid) as $orgid){ + if($parentids=C::t('organization')->fetch_parent_by_orgid($orgid)){ + $orgids=array_merge($orgids,$parentids); + } + } + if($orgids){ + $appids=C::t('app_organization')->fetch_appids_by_orgid($orgids); + }else{ + $appids=array(); + } + foreach(DB::fetch_all("select appid from %t where appid NOT IN(%n) ",array($this->_table,$appids)) as $value){ + $paichu_appids[]=$value['appid']; + } + + return $paichu_appids; + } + public function fetch_orgids_by_appid($appid){ + $orgids=array(); + $arr=DB::fetch_all("select orgid from %t where appid = %d ",array($this->_table,$appid)); + foreach($arr as $value){ + $orgids[]=$value['orgid']; + } + return $orgids; + } + + +} +?> diff --git a/core/class/table/table_app_pic.php b/core/class/table/table_app_pic.php new file mode 100644 index 0000000..b2ffa43 --- /dev/null +++ b/core/class/table/table_app_pic.php @@ -0,0 +1,73 @@ +_table = 'app_pic'; + $this->_pk = 'picid'; + /*$this->_pre_cache_key = 'app_pic_'; + $this->_cache_ttl = 0;*/ + + parent::__construct(); + } + public function delete_by_appid($appids){ //通过应用id删除应用图片 + if(!$appids) return; + if(!is_array($appids)){ + $appids=array($appids); + } + $data=DB::fetch_all("SELECT * FROM %t WHERE appid IN(%n)",array($this->_table,$appids)); + + foreach($data as $value){ + if($value['picid']) $this->delete_by_picid($value['picid']); + } + return true; + } + public function delete_by_picid($picid){ //删除应用图片 + global $_G; + if(!$data=$this->fetch($picid)){ + return false; + } + if($data['aid']){ + C::t('attachment')->delete_by_aid($data['aid']); + $this->delete($picid); + } + return true; + } + + public function fetch($picid,$force=false){ //返回一条数据同时加载attachment表数据库数据 + $picid = intval($picid); + $data = array(); + if($force || ($picid && $data = $this->fetch_cache($picid) === false)) { + $data=DB::fetch_first("SELECT * FROM %t WHERE picid= %d ", array($this->_table,$picid)); + $attachment= array(); + if($data['aid']) $attachment=C::t('attachment')->fetch($data['aid']); + $data=array_merge($attachment,$data); + if(!empty($data)) $this->store_cache($picid, $data, $this->_cache_ttl); + } + return $data; + } + public function fetch_all_by_appid($appid,$iscount=false,$force=false){ //返回某个应用的全部图片 + $appid=intval($appid); + $data=array(); + if($force || ($appid && ($data = $this->fetch_cache($appid,'app_pic_by_appid_')) === false)) { + foreach(DB::fetch_all("select picid from %t where appid= %d",array($this->_table,$appid)) as $value){ + $data[$value['picid']]=$this->fetch($value['picid'],$force); + } + if(!empty($data)) $this->store_cache($appid, $data, 3600,'app_pic_by_appid_'); + } + + return $iscount?count($data):$data; + } +} +?> diff --git a/core/class/table/table_app_relative.php b/core/class/table/table_app_relative.php new file mode 100644 index 0000000..ba762d0 --- /dev/null +++ b/core/class/table/table_app_relative.php @@ -0,0 +1,61 @@ +_table = 'app_relative'; + $this->_pk = 'rid'; + //$this->_pre_cache_key = 'app_relative_'; + //$this->_cache_ttl = 0; + + parent::__construct(); + } + + public function update_by_appid($appid,$tagids){ + //先删除有关此appid的部分 + self::delete_by_appid($appid); + foreach($tagids as $tagid){ + DB::insert($this->_table,array('appid'=>intval($appid),'tagid'=>intval($tagid))); + } + } + public function delete_by_appid($appid){ + $tagids=array(); + foreach(DB::fetch_all("select tagid from %t where appid=%d",array($this->_table,$appid)) as $value){ + $tagids[]=$value['tagid']; + } + C::t('app_tag')->delete_by_tagid($tagids); + DB::query("DELETE FROM %t WHERE appid= %d ",array($this->_table,$appid)); + } + public function fetch_all_by_tagid($tagid,$count=false){ + $tagid=intval($tagid); + if($count) return DB::result_first("select COUNT(*) from %t WHERE tagid= %d ",array($this->_table,$tagid)); + else return DB::fetch_all("SELECT * FROM %t WHERE tagid = %d ",array($this->_table,$tagid)); + } + public function fetch_all_by_appid($appid,$count=false){ + $appid=intval($appid); + if($count) return DB::result_first("select COUNT(*) from %t r LEFT JOIN %t t ON r.tagid=t.tagid WHERE t.tagid>0 and r.appid = %d ",array($this->_table,'app_tag',$appid)); + else return DB::fetch_all("SELECT t.* FROM %t r LEFT JOIN %t t ON r.tagid=t.tagid WHERE t.tagid>0 and r.appid = %d ",array($this->_table,'app_tag',$appid)); + } + public function fetch_appids_by_tagid($tagid){ + $appids=array(); + foreach(DB::fetch_all("select appid from %t where tagid=%d",array($this->_table,$tagid)) as $value){ + $appids[]=$value['appid']; + } + return $appids; + } + +} + +?> diff --git a/core/class/table/table_app_tag.php b/core/class/table/table_app_tag.php new file mode 100644 index 0000000..61a47ba --- /dev/null +++ b/core/class/table/table_app_tag.php @@ -0,0 +1,95 @@ +_table = 'app_tag'; + $this->_pk = 'tagid'; + + parent::__construct(); + } + + + public function addtags($tags,$appid) { + if(!$tags){ + C::t('app_relative')->delete_by_appid($appid); + return; + } + if(!is_array($tags)){ + if(strpos($tags,"','")!==false){ + $tagnames=explode("','",trim($tags,"'")); + }elseif(strpos($tags,',')!==false){ + $tagnames=explode(',',trim($tags)); + }else{ + $tagnames=array(trim($tags,"'")); + } + }else{ + $tagnames=$tags; + } + + + $tagarr=DB::fetch_all('SELECT tagid,tagname FROM '.DB::table($this->_table)." WHERE tagname IN( ".dimplode($tagnames).")"); + $have_tagnames=array(); + $have_tagids=array(); + + foreach($tagarr as $tagid => $value){ + $have_tagnames[]=$value['tagname']; + $have_tagids[]=$value['tagid']; + } + //已经存在的增加hot +1; + DB::query("UPDATE ".DB::table($this->_table)." SET hot=hot+1 WHERE tagid IN(%n)",array($have_tagids)); + $insert_names=array_diff($tagnames,$have_tagnames); + foreach($insert_names as $name){ + $have_tagids[]=self::insert(array('tagname'=>$name, 'dateline'=>TIMESTAMP, 'hot'=>1),1); + } + //插入关系表 + C::t('app_relative')->update_by_appid($appid,$have_tagids); + } + public function delete_by_tagid($tagids){ + DB::query("UPDATE ".DB::table($this->_table)." SET hot=hot-1 WHERE tagid IN(".dimplode($tagids).")"); + DB::delete($this->_table, array('hot'=>0)); + } + public function deletetags($tags) { + if(!$tags) return; + if(!is_array($tags)){ + if(strpos($tags,"','")!==false){ + $tagnames=explode("','",trim($tags,"'")); + }elseif(strpos($tags,',')!==false){ + $tagnames=explode(',',trim($tags)); + }else{ + $tagnames=array($tags); + } + }else{ + $tagnames=$tags; + } + $tagarr=DB::fetch_all('SELECT tagid,tagname,hot FROM '.DB::table($this->_table)." WHERE tagname IN (".dimplode($tagnames).")"); + $have_tagids=array(); + $delete_tagids=array(); + foreach($tagarr as $tagid => $value){ + if($value['hot']>1) $have_tagids[]=$value['tagname']; + elseif($value['hot']<1){ + $delete_tagids[]=$value['tagid']; + } + } + //已经存在的且hot>1的-1; + DB::query("UPDATE ".DB::table($this->_table)." SET hot=hot-1 WHERE tagid IN(".dimplode($have_tagids).")"); + //已经存在的且hot<=1的删除; + DB::query("DELETE FROM ".DB::table($this->_table)." WHERE tagid IN(".dimplode($delete_tagids).")"); + + } + +} + +?> diff --git a/core/class/table/table_app_user.php b/core/class/table/table_app_user.php new file mode 100644 index 0000000..d5d6588 --- /dev/null +++ b/core/class/table/table_app_user.php @@ -0,0 +1,65 @@ +_table = 'app_user'; + $this->_pk = 'id'; + parent::__construct(); + } + public function delete_by_uid_appid($uid,$appid){ + if(!$appid) return false; + return DB::delete($this->_table," appid='{$appid}' and uid='{$uid}'"); + } + public function delete_by_appid($appid){ + if(!$appid) return false; + return DB::delete($this->_table," appid='{$appid}'"); + } + public function update_lasttime($uid,$appid,$lasttime){ + if(!$uid) return false; + if(DB::query("update ".DB::table($this->_table)." set lasttime=".intval($lasttime).", num=num+1 where appid='{$appid}' and uid='{$uid}'")){ + + }else{ + parent::insert(array('uid'=>$uid,'appid'=>$appid,'lasttime'=>$lasttime,'dateline'=>TIMESTAMP,'num'=>1),false,true); + } + } + + public function insert_by_uid($uid,$appids,$isall=0){ + if(!$appids) return false; + if(!is_array($appids)) $appids=array($appids); + //删除原来的 + $oids=array(); + $delids=array(); + $insertids=array(); + $oarr=DB::fetch_all("select * from ".DB::table('app_user')." where uid='{$uid}'"); + foreach($oarr as $value){ + $oids[]=$value['appid']; + if( !in_array($value['appid'],$appids)) $delids[]=$value['id']; + } + if($isall && $delids) { + self::delete($delids); + } + foreach($appids as $appid){ + if(!in_array($appid,$oids)) DB::insert('app_user',array('uid'=>$uid,'appid'=>$appid,'dateline'=>TIMESTAMP,'num'=>1)); + } + return true; + } + public function fetch_all_appids_by_uid($uid){ + $data=array(); + foreach(DB::fetch_all("select appid from %t where uid=%d",array($this->_table,$uid)) as $value){ + $data[]=$value['appid']; + } + return $data; + } +} +?> diff --git a/core/class/table/table_attachment.php b/core/class/table/table_attachment.php new file mode 100644 index 0000000..ab30c30 --- /dev/null +++ b/core/class/table/table_attachment.php @@ -0,0 +1,161 @@ +_table = 'attachment'; + $this->_pk = 'aid'; + $this->_pre_cache_key = 'attachment_'; + $this->_cache_ttl = 0; + parent::__construct(); + } + public function setUnrun_by_aid($aid,$r){//设置允许运行,如果文件在本地同时修改实际文件名,增加无法运行的后缀; + $data=parent::fetch($aid); + if($data['remote']==0 || $data['remote']==1){//文件在本地,修改文件名 + if($r>0){ + $earr=explode('.',$data['attachment']); + foreach($earr as $key=> $ext){ + if(in_array(strtolower($ext),array($data['filetype'],'dzz'))) unset($earr[$key]); + } + $tattachment=implode('.',$earr).'.dzz'; + if(is_file(getglobal('setting/attachdir').'./'.$data['attachment']) && @rename(getglobal('setting/attachdir').'./'.$data['attachment'],getglobal('setting/attachdir').'./'.$tattachment)){ + return parent::update($aid,array('unrun'=>$r,'attachment'=>$tattachment)); + } + + }else{ + $earr=explode('.',$data['attachment']); + foreach($earr as $key=> $ext){ + if(in_array(strtolower($ext),array($data['filetype'],'dzz'))) unset($earr[$key]); + } + $tattachment=implode('.',$earr).'.'.$data['filetype']; + if(is_file(getglobal('setting/attachdir').'./'.$data['attachment']) && @rename(getglobal('setting/attachdir').'./'.$data['attachment'],getglobal('setting/attachdir').'./'.$tattachment)){ + return parent::update($aid,array('unrun'=>$r,'attachment'=>$tattachment)); + } + } + } + return false; + } + public function getThumbByAid($aid,$width=256,$height=256,$original=0){ //通过附件获取缩略图 + //可以让$aid 带入$attach数组. + if(!is_array($aid)){ + $attach=self::fetch($aid); + }else{ + $attach=$aid; + } + if(!$width ||!$height) $original=1; + /*$bz=io_remote::getBzByRemoteid($attach['remote']); + if($bz=='dzz'){*/ + $path='attach::'.$attach['aid']; + /*}else{ + $path=$bz.'/'.$attach['attachment']; + }*/ + return (defined('DZZSCRIPT')?DZZSCRIPT:'index.php').'?mod=io&op=thumbnail&width='.$width.'&height='.$height.'&original='.$original.'&path='.dzzencode($path); + } + public function get_total_filesize() { + $attachsize = 0; + $attachsize = DB::result_first("SELECT SUM(filesize) FROM ".DB::table($this->table)); + return $attachsize; + } + public function addcopy_by_aid($aids,$ceof=1){ + if(!is_array($aids)) $aids=array($aids); + + if($ceof>0){ + DB::query("update %t set copys=copys+%d where aid IN(%n)",array($this->_table,$ceof,$aids)); + }else{ + DB::query("update %t set copys=copys-%d where aid IN(%n)",array($this->_table,abs($ceof),$aids)); + } + $this->clear_cache($aids); + } + public function delete_by_aid($aid){ //删除附件 + global $_G; + if(!$data=$this->fetch($aid)){ + return false; + } + if($data['copys']>1){ + return $this->update($aid,array('copys'=>$data['copys']-1)); + }else{ + if(io_remote::DeleteFromSpace($data)){ + return $this->delete($aid); + }else{ + return false; + } + } + return true; + } + public function fetch_by_md5($md5){ //通过md5值返回一条数据 + return DB::fetch_first("SELECT * FROM %t WHERE md5 = %s ",array($this->table,$md5)); + } + public function getSizeByRemote($remoteid){ //统计占用空间 + if($remoteid<2){ + return DB::result_first("SELECT sum(filesize) FROM %t WHERE remote <2 and copys>0 ",array($this->table)); + }else{ + return DB::result_first("SELECT sum(filesize) FROM %t WHERE remote = %d and copys>0 ",array($this->table,$remoteid)); + } + + } + public function getAttachByFilter($filter,$sizecount=false){ //统计占用空间 + $where='copys>0 and remote!='.$filter['remoteid']; + if($filter['oremoteid']){ + if($filter['oremoteid']<2){ + $where.=" and remote<2"; + }else{ + $where.=" and remote= '{$filter[oremoteid]}'"; + } + } + + if($filter['aid']){ + $where.=" and aid='{$filter['aid']}'"; + } + $filter['sizelt']=intval($filter['sizelt']*1024*1024); + if($filter['sizelt']>0){ + $where.=" and filesize>'$filter[sizelt]'"; + } + $filter['sizegt']=intval($filter['sizegt']*1024*1024); + if($filter['sizegt']>0){ + $where.=" and filesize<'$filter[sizegt]'"; + } + if($filter['exts']){ + $extarr=explode(',',$filter['exts']); + if($extarr){ + $where.=" and filetype IN (".dimplode($extarr).")"; + } + } + if($filter['dateline']){ + $where.=" and dateline>='{$filter[dateline]}'"; + } + if($filter['aid1']){ + $where.=" and aid>'{$filter[aid1]}'"; + } + + if($filter['ignore']){ + $ignores=explode(',',$filter['ignore']); + if($ignores){ + $where.=" and aid NOT IN (".dimplode($ignores).")"; + } + } + if($sizecount) return DB::result_first("SELECT sum(filesize) FROM ".DB::table($this->_table)." WHERE $where "); + else return DB::fetch_first("SELECT * FROM ".DB::table($this->_table)." WHERE $where order by aid"); + + } + public function insert($setarr,$return_insert_id=1){ + if($aid=parent::insert($setarr,$return_insert_id)){ + Hook::listen('table_attachment_insert', $aid);//插入附件表时的挂载点 + return $aid; + } + return false; + } +} + +?> diff --git a/core/class/table/table_cache.php b/core/class/table/table_cache.php new file mode 100644 index 0000000..a941583 --- /dev/null +++ b/core/class/table/table_cache.php @@ -0,0 +1,26 @@ +_table = 'cache'; + $this->_pk = 'cachekey'; + + parent::__construct(); + } + +} + +?> diff --git a/core/class/table/table_collect.php b/core/class/table/table_collect.php new file mode 100644 index 0000000..db48f30 --- /dev/null +++ b/core/class/table/table_collect.php @@ -0,0 +1,35 @@ +_table = 'collect'; + $this->_pk = 'cid'; + parent::__construct(); + } + public function delete_by_cid($cid){ + $lid=intval($cid); + $link=self::fetch($cid); + if($link['cid']){ + $copys=DB::result_first("select copys from ".DB::table('collect')." where cid='{$link[cid]}' and type = 'link'"); + if($copys<=1){ + return DB::delete('collect',"cid='{$link[cid]}'"); + }else{ + return DB::update('collect',array('copys'=>$copys-1),"cid='{$link[cid]}'"); + } + } + } + public function addcopy_by_cid($cid,$ceof=1){ + if(!is_array($cid)) $aids=array($cid); + + if($ceof>0){ + DB::query("update %t set copys=copys+%d where cid IN(%n)",array($this->_table,$ceof,$cid)); + }else{ + DB::query("update %t set copys=copys-%d where cid IN(%n)",array($this->_table,abs($ceof),$cid)); + } + } +} \ No newline at end of file diff --git a/core/class/table/table_comment.php b/core/class/table/table_comment.php new file mode 100644 index 0000000..a8a4462 --- /dev/null +++ b/core/class/table/table_comment.php @@ -0,0 +1,172 @@ +_table = 'comment'; + $this->_pk = 'cid'; + $this->_pre_cache_key = 'comment_'; + $this->_cache_ttl = 60*60; + parent::__construct(); + } + + public function insert_by_cid($arr,$ats,$attach){ + if($arr['cid']=parent::insert($arr,1)){ + /*if($arr['rcid'] && $rdata=parent::fetch($arr['rcid']) && !in_array($rdata['authorid'],$ats)){ + $ats[]=$rdata['authorid']; + }*/ + if($ats){ + C::t('comment_at')->insert_by_cid($arr['cid'],($ats)); + } + if($attach) C::t('comment_attach')->insert_by_cid($arr['cid'],$attach); + + if($arr['module']){ + + @include_once DZZ_ROOT.'./dzz/'.$arr['module'].'/class/table/table_'.$arr['idtype'].'.php'; + }else{ + @include_once DZZ_ROOT.'./core/class/table/table_'.$arr['idtype'].'.php'; + } + if(class_exists('table_'.$arr['idtype']) && method_exists('table_'.$arr['idtype'],'callback_by_comment')){ + $arr['message']=dzzcode($arr['message']); + C::t($arr['idtype'])->callback_by_comment($arr,'add',$ats); + } + } + return $arr['cid']; + } + public function update_by_cid($cid,$message,$rcid,$attach){ + $ret=0; + $ret+=parent::update($cid,array('message'=>$message,'rcid'=>$rcid,'edituid'=>getglobal('uid'),'edittime'=>TIMESTAMP)); + + $ret+=C::t('comment_attach')->update_by_cid($cid,$attach); + + return $ret; + } + public function delete_by_cid($cid){ + if(!$data=parent::fetch($cid)) return false; + $delcids=array($cid); + foreach(DB::fetch_all("select cid from %t where pcid=%d ",array($this->_table,$cid)) as $value){ + $delcids[]=$value['cid']; + } + if($return=parent::delete($delcids)){ + //删除@ + C::t('comment_at')->delete_by_cid($delcids); + //删除附件 + C::t('comment_attach')->delete_by_cid($delcids); + if($data['module']){ + @include_once DZZ_ROOT.'dzz/'.$data['module'].'/class/table/table_'.$data['idtype'].'.php'; + }else{ + @include_once DZZ_ROOT.'core/class/table/table_'.$data['idtype'].'.php'; + } + if(class_exists('table_'.$data['idtype']) && method_exists('table_'.$data['idtype'],'callback_by_comment')){ + C::t($data['idtype'])->callback_by_comment($data,'delete'); + } + return $return; + }else{ + return false; + } + } + public function delete_by_id_idtype($ids,$idtype){ + $ids=(array)$ids; + $dels=array(); + foreach(DB::fetch_all("select * from %t where id IN (%n) and idtype=%s",array($this->_table,$ids,$idtype)) as $value){ + $dels[]=$value['cid']; + } + if($return=parent::delete($dels)){ + //删除@ + C::t('comment_at')->delete_by_cid($dels); + //删除附件 + C::t('comment_attach')->delete_by_cid($dels); + } + return parent::delete($dels); + } + public function fetch_all_by_idtype($id,$idtype,$limit,$iscount=false){ + + $limitsql=''; + if($limit){ + $limit=explode('-',$limit); + if(count($limit)>1){ + $limitsql.=" limit ".intval($limit[0]).",".intval($limit[1]); + }else{ + $limitsql.=" limit ".intval($limit[0]); + } + } + + if($iscount) return DB::result_first("select COUNT(*) from %t where id=%s and idtype=%s and pcid=0",array($this->_table,$id,$idtype)); + $data=array(); + foreach(DB::fetch_all("select * from %t where id=%s and idtype=%s and pcid=0 order by dateline DESC $limitsql",array($this->_table,$id,$idtype)) as $value){ + $value['message']=dzzcode($value['message']); + $value['dateline']=dgmdate($value['dateline'],'u'); + $value['replies']=DB::result_first("select COUNT(*) from %t where pcid=%d",array($this->_table,$value['cid'])); + $value['replys']=self::fetch_all_by_pcid($value['cid'],5); + $value['attachs']=C::t('comment_attach')->fetch_all_by_cid($value['cid']); + $data[]=$value; + } + return $data; + } + public function fetch_all_by_pcid($pcid,$limit,$iscount=false){ + $limitsql=''; + if($limit){ + $limit=explode('-',$limit); + if(count($limit)>1){ + $limitsql.=" limit ".intval($limit[0]).",".intval($limit[1]); + }else{ + $limitsql.=" limit ".intval($limit[0]); + } + } + if($iscount) return DB::result_first("select COUNT(*) from %t where pcid=%d ",array($this->_table,$pcid)); + $data=array(); + foreach(DB::fetch_all("select * from %t where pcid=%d order by dateline DESC $limitsql",array($this->_table,$pcid)) as $value){ + $value['message']=dzzcode($value['message']); + $value['dateline']=dgmdate($value['dateline'],'u'); + $value['attachs']=C::t('comment_attach')->fetch_all_by_cid($value['cid']); + if($value['rcid']){ + $value['rpost']=parent::fetch($value['rcid']); + } + + $data[]=$value; + } + return $data; + } + + public function copy_by_id_idtype($oid,$id,$idtype){ + $return=0; + foreach(DB::fetch_all("select * from %t where id=%s and idtype=%s and pcid='0'",array($this->_table,$oid,$idtype)) as $value){ + $ocid=$value['cid']; + unset($value['cid']); + $value['id']=$id; + if($value['cid']=parent::insert($value,1)){ + C::t('comment_at')->copy_by_cid($ocid,$value['cid']); + C::t('comment_attach')->copy_by_cid($ocid,$value['cid']); + $return+=1; + //拷贝子评论 + foreach(DB::fetch_all("select * from %t where pcid=%d ",array($this->_table,$ocid)) as $value1){ + $ocid=$value1['cid']; + unset($value1['cid']); + $value1['pcid']=$value['cid']; + $value1['id']=$id; + $value1['rcid']=0; + if(parent::insert($value1,1)){ + C::t('comment_at')->copy_by_cid($ocid,$value['cid']); + C::t('comment_attach')->copy_by_cid($ocid,$value['cid']); + } + } + } + } + return $return; + } + +} + +?> diff --git a/core/class/table/table_comment_at.php b/core/class/table/table_comment_at.php new file mode 100644 index 0000000..b7df66f --- /dev/null +++ b/core/class/table/table_comment_at.php @@ -0,0 +1,55 @@ +_table = 'comment_at'; + $this->_pk = ''; + + parent::__construct(); + } + public function fetch_all_cids_by_uid($uid,$timestamp=0,$count=0){ + $cids=array(); + if($count) return DB::result_first("select COUNT(*) from %t where uid=%d and dateline>%d",array($this->_table,$uid,$timestamp)); + foreach(DB::fetch_all("select cid from %t where uid=%d and dateline>%d",array($this->_table,$uid,$timestamp)) as $value){ + $tids[]=$value['cid']; + } + return array_unique($cids); + } + public function insert_by_cid($cid,$uids){ + if(!$cid || !$uids) return false; + foreach($uids as $uid){ + parent::insert(array('cid'=>$cid,'uid'=>$uid,'dateline'=>TIMESTAMP),0,1); + } + + } + public function delete_by_cid($cids){ + if(!$cids) return false; + if(!is_array($cids)){ + $cids=array($cids); + } + return DB::delete($this->_table,"cid IN (".dimplode($cids).")"); + } + public function copy_by_cid($ocid,$cid){ + foreach(DB::fetch_all("select * from %t where cid=%d",array($this->_table,$ocid)) as $value){ + $value['cid']=$cid; + parent::insert($value,0,1); + } + return 0; + } + +} + +?> diff --git a/core/class/table/table_comment_attach.php b/core/class/table/table_comment_attach.php new file mode 100644 index 0000000..5ea5f95 --- /dev/null +++ b/core/class/table/table_comment_attach.php @@ -0,0 +1,180 @@ +_table = 'comment_attach'; + $this->_pk = 'qid'; + $this->_pre_cache_key = 'comment_attach_'; + $this->_cache_ttl = 60*60; + parent::__construct(); + } + public function fetch_by_qid($qid){ + global $_G; + if(!$data=self::fetch($qid)) return false; + if($data['aid']>0){ + $attach=C::t('attachment')->fetch($data['aid']); + if(in_array(strtolower($attach['filetype']),array('png','jpeg','jpg','gif'))){ + $attach['img']=C::t('attachment')->getThumbByAid($attach,120,80); + $attach['isimage']=1; + $attach['type']='image'; + }else{ + $attach['img']=geticonfromext($attach['filetype'],''); + $attach['isimage']=0; + } + $attach['url']=getAttachUrl($attach); + + $attach['filename']=$data['title']; + $data = array_merge($attach,$data); + } + return $data; + } + public function insert_by_cid($cid,$attach){ + //处理附件 + foreach($attach['title'] as $key=>$value){ + $setarr=array('cid'=>$cid, + 'dateline'=>TIMESTAMP, + 'aid'=>intval($attach['aid'][$key]), + 'title'=>getstr($value), + 'type'=>getstr($attach['type'][$key]), + 'img'=>getstr($attach['img'][$key]), + 'url'=>getstr($attach['url'][$key]), + 'ext'=>getstr($attach['ext'][$key]) + ); + + if(parent::insert($setarr)){ + if($setarr['aid']>0) C::t('attachment')->addcopy_by_aid($setarr['aid']); + if($setarr['type']=='link'){ + $imgarr=$setarr['img']?explode('icon',$setarr['img']):array(); + if(isset($imgarr[1]) && ($did=DB::result_first("select did from %t where pic=%s",array('icon','icon'.$imgarr[1])))) C::t('icon')->update_copys_by_did($did); + } + } + } + } + public function update_by_cid($cid,$attach){ + $qids=array(); + $ret=0; + foreach(DB::fetch_all("select qid from %t where cid=%d",array($this->_table,$cid)) as $value){ + $qids[$value['qid']]=$value['qid']; + } + + foreach($attach['title'] as $key=> $value){ + $qid=intval($attach['qid'][$key]); + if($qid>0){ + unset($qids[$qid]); + }else{ + $setarr=array('cid'=>$cid, + 'dateline'=>TIMESTAMP, + 'aid'=>intval($attach['aid'][$key]), + 'title'=>trim($value), + 'type'=>trim($attach['type'][$key]), + 'img'=>trim($attach['img'][$key]), + 'url'=>trim($attach['url'][$key]), + 'ext'=>trim($attach['ext'][$key]) + ); + if($ret+=parent::insert($setarr)){ + if($setarr['aid']) C::t('attachment')->addcopy_by_aid($setarr['aid']); + if($setarr['type']=='link'){ + $imgarr=$setarr['img']?explode('icon',$setarr['img']):array(); + if(isset($imgarr[1]) && ($did=DB::result_first("select did from %t where pic=%s",array('icon','icon'.$imgarr[1])))) C::t('icon')->update_copys_by_did($did,-1); + } + } + } + } + if($qids) $ret+=self::delete_by_qid($qids); + return $ret; + } + public function delete_by_qid($qids){ + $qids=(array)$qids; + $ret=0; + foreach(DB::fetch_all("select qid,aid,type,img from %t where qid IN(%n)",array('comment_attach',$qids)) as $value){ + if(parent::delete($value['qid'])){ + $ret+=1; + if($value['aid']>0) C::t('attachment')->delete_by_aid($value['aid']); + if($value['type']=='link'){ + $imgarr=$value['img']?explode('icon',$value['img']):array(); + if(isset($imgarr[1]) && ($did=DB::result_first("select did from %t where pic=%s",array('icon','icon'.$imgarr[1])))) C::t('icon')->update_copys_by_did($did,-1); + } + } + } + return $ret; + } + public function delete_by_cid($cids){ + $cids=(array)$cids; + $ret=0; + foreach(DB::fetch_all("select qid,aid,type,img from %t where cid IN (%n) ",array('comment_attach',$cids)) as $value){ + if(parent::delete($value['qid'])){ + $ret+=1; + if($value['aid']>0) C::t('attachment')->delete_by_aid($value['aid']); + if($value['type']=='link'){ + $imgarr=$value['img']?explode('icon',$value['img']):array(); + if(isset($imgarr[1]) && ($did=DB::result_first("select did from %t where pic=%s",array('icon','icon'.$imgarr[1])))) C::t('icon')->update_copys_by_did($did,-1); + } + } + } + return $ret; + } + + public function fetch_all_by_cid($cid){ + global $_G; + $data=array(); + //$openext=C::t('app_open')->fetch_all_orderby_ext($_G['uid']); + foreach(DB::fetch_all("select * from %t where cid= %d",array($this->_table,$cid)) as $value){ + $value['title']=getstr($value['title']); + $value['type']=getstr($value['type']); + $value['url']=getstr($value['url']); + $value['ext']=getstr($value['ext']); + $value['img']=getstr($value['img']); + + if($value['aid']>0){ + $attach=C::t('attachment')->fetch($value['aid']); + if(in_array(strtolower($attach['filetype']),array('png','jpeg','jpg','gif','bmp'))){ + $attach['img']=C::t('attachment')->getThumbByAid($attach); + $attach['isimage']=1; + $value['type']='image'; + }else{ + $attach['img']=geticonfromext($attach['filetype'],''); + $attach['isimage']=0; + } + $attach['url']=getAttachUrl($attach); + //if(isset($openext[$attach['filetype']])) + $attach['preview']=1; + $attach['filesize']=formatsize($attach['filesize']); + $data[$value['qid']]=array_merge($value,$attach); + }else{ + $value['preview']=1; + $data[$value['qid']]=$value; + } + + } + return $data; + } + public function copy_by_cid($ocid,$cid){ + $aids=array(); + foreach(DB::fetch_all("select * from %t where cid=%d",array($this->_table,$ocid)) as $value){ + unset($value['qid']); + $value['cid']=$cid; + if(parent::insert($value)){ + if($value['type']=='attach' && $value['aid']>0) C::t('attachment')->addcopy_by_aid($value['aid']); + if($value['type']=='link'){ + $imgarr=$value['img']?explode('icon',$value['img']):array(); + if(isset($imgarr[1]) && ($did=DB::result_first("select did from %t where pic=%s",array('icon','icon'.$imgarr[1])))) C::t('icon')->update_copys_by_did($did); + } + } + } + return 0; + } +} +?> diff --git a/core/class/table/table_connect.php b/core/class/table/table_connect.php new file mode 100644 index 0000000..26e795f --- /dev/null +++ b/core/class/table/table_connect.php @@ -0,0 +1,77 @@ +_table = 'connect'; + $this->_pk = 'bz'; + $this->_pre_cache_key = 'connect_'; + $this->_cache_ttl = 60*60; + parent::__construct(); + } + public function fetch_all_by_available($onlyuser=false){ + $data=array(); + if($onlyuser) $available=1; + else $available=0; + $query=DB::query("SELECT * FROM ".DB::table($this->_table)." WHERE available > '{$available}' and type!='local' ORDER BY disp"); + while($value=DB::fetch($query)){ + //检测可用性 + if($value['type']=='pan' && (empty($value['key']) || empty($value['secret']))){ + $value['available']=0; + $value['warning']=lang('please_open_after_setting'); + continue; + } + if(!is_file(DZZ_ROOT.'./core/class/io/io_'.($value['bz']).'.php')){ + $value['available']=0; + $value['warning']='api'.lang('typename_attach').':io_'.($value['bz']).'.php'.lang('inexistence').'!'; + continue; + } + + $data[$value['bz']]=$value; + } + return $data; + } + + public function fetch_all_folderdata($uid){ + $data=self::fetch_all_by_available(); + $folderdata=array(); + foreach($data as $value){ + foreach(DB::fetch_all("select id from ".DB::table($value['dname'])." where uid>0 && uid='{$uid}'") as $value1){ + + $arr=C::t($value['dname'])->fetch_by_id($value1['id']); + $folderdata[$arr['fid']]=$arr; + } + } + return $folderdata; + } + public function fetch_all_bz(){ + $data=array(); + foreach(DB::fetch_all("select bz from %t where 1",array($this->_table)) as $value){ + $data[]=$value['bz']; + } + return $data; + } + public function delete_by_bz($bz){ + if($bz=='dzz') return false; //dzz是内置,不能删除 + $data=self::fetch($bz); + if(is_file(DZZ_ROOT.'./core/class/table/table_'.$data['dname'].'.php')){ + C::t($data['dname'])->delete_by_bz($bz); + } + return self::delete($bz); + } +} + +?> diff --git a/core/class/table/table_connect_disk.php b/core/class/table/table_connect_disk.php new file mode 100644 index 0000000..bb73e6d --- /dev/null +++ b/core/class/table/table_connect_disk.php @@ -0,0 +1,82 @@ +_table = 'connect_disk'; + $this->_pk = 'id'; + $this->_pre_cache_key = 'connect_disk_'; + $this->_cache_ttl = 300; + parent::__construct(); + } + public function fetch_by_id($id){ + + $value=parent::fetch($id); + $cloud=DB::fetch_first("select * from ".DB::table('connect')." where bz='{$value['bz']}'"); + $data=array( + 'id'=>$value['id'], + 'fid'=>md5($cloud['bz'].':'.$value['id'].':'.$cloud['root']), + 'pfid'=>0, + 'fname'=>$value['cloudname'], + 'ficon'=>'dzz/images/default/system/'.$cloud['bz'].'.png', + 'bz'=>$cloud['bz'].':'.$value['id'].':', + 'path'=>$cloud['bz'].':'.$value['id'].':'.$cloud['root'], + 'type'=>'disk', + 'fsperm'=>perm_FolderSPerm::flagPower($cloud['bz']), + 'perm'=>perm_binPerm::getGroupPower('all'), + 'flag'=>$cloud['bz'], + 'iconview'=>1, + 'disp'=>'0', + ); + + return $data; + } + public function fetch_all_by_id($ids){ + $data=array(); + foreach($ids as $id){ + $value=self::fetch_by_id($id); + $data[$value['fid']]=$value; + } + return $data; + } + public function delete_by_id($id){ + $return=array(); + $data=parent::fetch($id); + if(parent::delete($id)){ + $return['msg']='success'; + //C::t('source_shortcut')->delete_by_bz($data['bz'].':'.$id.':',true);//删除快捷方式; + //删除图片缓存文件 + $imgcache=getglobal('setting/attachdir').'./imgcache/'.$data['bz'].'/'.$id.'/'; + removedirectory($imgcache); + } + return $return; + } + public function delete_by_uid($uid){ + if(!$uid) return 0; + foreach(DB::fetch_all("select id from %t where uid=%d",array($this->_table,$uid)) as $value){ + self::delete_by_id($value['id']); + } + return true; + } + public function delete_by_bz($bz){ + foreach(DB::fetch_all("select id from %t where bz=%s",array($this->_table,$bz)) as $value){ + self::delete_by_id($value['id']); + } + } +} + +?> diff --git a/core/class/table/table_connect_ftp.php b/core/class/table/table_connect_ftp.php new file mode 100644 index 0000000..dc9b23a --- /dev/null +++ b/core/class/table/table_connect_ftp.php @@ -0,0 +1,82 @@ +_table = 'connect_ftp'; + $this->_pk = 'id'; + $this->_pre_cache_key = 'connect_ftp_'; + $this->_cache_ttl = 300; + parent::__construct(); + } + public function fetch_by_id($id){ + + $value=self::fetch($id); + $cloud=DB::fetch_first("select * from ".DB::table('connect')." where bz='{$value['bz']}'"); + $data=array( + 'id'=>$value['id'], + 'fid'=>md5($cloud['bz'].':'.$value['id'].':'.$cloud['root']), + 'pfid'=>0, + 'fname'=>$value['cloudname'], + 'ficon'=>'dzz/images/default/system/'.$cloud['bz'].'.png', + 'bz'=>$cloud['bz'].':'.$value['id'].':', + 'path'=>$cloud['bz'].':'.$value['id'].':'.$cloud['root'], + 'type'=>'ftp', + 'fsperm'=>perm_FolderSPerm::flagPower($cloud['bz']), + 'perm'=>perm_binPerm::getGroupPower('all'), + 'flag'=>$cloud['bz'], + 'iconview'=>1, + 'disp'=>'0', + ); + + return $data; + } + public function fetch_all_by_id($ids){ + $data=array(); + foreach($ids as $id){ + $value=self::fetch_by_id($id); + $data[$value['fid']]=$value; + } + return $data; + } + public function delete_by_id($id){ + $return=array(); + $data=parent::fetch($id); + if(parent::delete($id)){ + $return['msg']='success'; + //C::t('source_shortcut')->delete_by_bz($data['bz'].':'.$id.':',true);//删除快捷方式; + //删除图片缓存文件 + $imgcache=getglobal('setting/attachdir').'./imgcache/'.$data['bz'].'/'.$id.'/'; + removedirectory($imgcache); + } + return $return; + } + public function delete_by_uid($uid){ + if(!$uid) return 0; + foreach(DB::fetch_all("select id from %t where uid=%d",array($this->_table,$uid)) as $value){ + self::delete_by_id($value['id']); + } + return true; + } + public function delete_by_bz($bz){ + foreach(DB::fetch_all("select id from %t where bz=%s",array($this->_table,$bz)) as $value){ + self::delete_by_id($value['id']); + } + } +} + +?> diff --git a/core/class/table/table_connect_onedrive.php b/core/class/table/table_connect_onedrive.php new file mode 100644 index 0000000..6aefcbe --- /dev/null +++ b/core/class/table/table_connect_onedrive.php @@ -0,0 +1,83 @@ +_table = 'connect_onedrive'; + $this->_pk = 'id'; + $this->_pre_cache_key = 'connect_onedrive_'; + $this->_cache_ttl = 300; + parent::__construct(); + } + public function fetch_by_id($id){ + + $value=self::fetch($id); + $cloud=DB::fetch_first("select * from ".DB::table('connect')." where bz='{$value['bz']}'"); + if(!$value['cloudname']) $value['cloudname']=$cloud['name'].':'.($value['cusername']?$value['cusername']:$cloud['cuid']); + $data=array( + 'id'=>$value['id'], + 'fid'=>md5($cloud['bz'].':'.$value['id'].':'.$cloud['root']), + 'pfid'=>0, + 'fname'=>$value['cloudname'], + 'ficon'=>'dzz/images/default/system/'.$cloud['bz'].'.png', + 'bz'=>$cloud['bz'].':'.$value['id'].':', + 'path'=>$cloud['bz'].':'.$value['id'].':'.$cloud['root'], + 'type'=>'pan', + 'fsperm'=>perm_FolderSPerm::flagPower($cloud['bz']), + 'perm'=>perm_binPerm::getGroupPower('all'), + 'flag'=>$cloud['bz'], + 'iconview'=>1, + 'disp'=>'0', + ); + + return $data; + } + public function fetch_all_by_id($ids){ + $data=array(); + foreach($ids as $id){ + $value=self::fetch_by_id($id); + $data[$value['fid']]=$value; + } + return $data; + } + public function delete_by_id($id){ + $return=array(); + $data=parent::fetch($id); + if(parent::delete($id)){ + $return['msg']='success'; + //C::t('source_shortcut')->delete_by_bz($data['bz'].':'.$id.':',true);//删除快捷方式; + //删除图片缓存文件 + $imgcache=getglobal('setting/attachdir').'./imgcache/'.$data['bz'].'/'.$id.'/'; + removedirectory($imgcache); + } + return $return; + } + public function delete_by_uid($uid){ + if(!$uid) return 0; + foreach(DB::fetch_all("select id from %t where uid=%d",array($this->_table,$uid)) as $value){ + self::delete_by_id($value['id']); + } + return true; + } + public function delete_by_bz($bz){ + foreach(DB::fetch_all("select id from %t where bz=%s",array($this->_table,$bz)) as $value){ + self::delete_by_id($value['id']); + } + } +} + +?> diff --git a/core/class/table/table_connect_pan.php b/core/class/table/table_connect_pan.php new file mode 100644 index 0000000..942727c --- /dev/null +++ b/core/class/table/table_connect_pan.php @@ -0,0 +1,83 @@ +_table = 'connect_pan'; + $this->_pk = 'id'; + $this->_pre_cache_key = 'connect_pan_'; + $this->_cache_ttl = 300; + parent::__construct(); + } + public function fetch_by_id($id){ + + $value=self::fetch($id); + $cloud=DB::fetch_first("select * from ".DB::table('connect')." where bz='{$value['bz']}'"); + if(!$value['cloudname']) $value['cloudname']=$cloud['name'].':'.($value['cusername']?$value['cusername']:$cloud['cuid']); + $data=array( + 'id'=>$value['id'], + 'fid'=>md5($cloud['bz'].':'.$value['id'].':'.$cloud['root']), + 'pfid'=>0, + 'fname'=>$value['cloudname'], + 'ficon'=>'dzz/images/default/system/'.$cloud['bz'].'.png', + 'bz'=>$cloud['bz'].':'.$value['id'].':', + 'path'=>$cloud['bz'].':'.$value['id'].':'.$cloud['root'], + 'type'=>'pan', + 'fsperm'=>perm_FolderSPerm::flagPower($cloud['bz']), + 'perm'=>perm_binPerm::getGroupPower('all'), + 'flag'=>$cloud['bz'], + 'iconview'=>1, + 'disp'=>'0', + ); + + return $data; + } + public function fetch_all_by_id($ids){ + $data=array(); + foreach($ids as $id){ + $value=self::fetch_by_id($id); + $data[$value['fid']]=$value; + } + return $data; + } + public function delete_by_id($id){ + $return=array(); + $data=parent::fetch($id); + if(parent::delete($id)){ + $return['msg']='success'; + //C::t('source_shortcut')->delete_by_bz($data['bz'].':'.$id.':',true);//删除快捷方式; + //删除图片缓存文件 + $imgcache=getglobal('setting/attachdir').'./imgcache/'.$data['bz'].'/'.$id.'/'; + removedirectory($imgcache); + } + return $return; + } + public function delete_by_uid($uid){ + if(!$uid) return 0; + foreach(DB::fetch_all("select id from %t where uid=%d",array($this->_table,$uid)) as $value){ + self::delete_by_id($value['id']); + } + return true; + } + public function delete_by_bz($bz){ + foreach(DB::fetch_all("select id from %t where bz=%s",array($this->_table,$bz)) as $value){ + self::delete_by_id($value['id']); + } + } +} + +?> diff --git a/core/class/table/table_connect_storage.php b/core/class/table/table_connect_storage.php new file mode 100644 index 0000000..9ba9441 --- /dev/null +++ b/core/class/table/table_connect_storage.php @@ -0,0 +1,84 @@ +_table = 'connect_storage'; + $this->_pk = 'id'; + /*$this->_pre_cache_key = 'connect_storage_'; + $this->_cache_ttl = 0;*/ + parent::__construct(); + } + public function fetch_by_id($id){ + + $value=self::fetch($id); + $cloud=DB::fetch_first("select * from ".DB::table('connect')." where bz='{$value['bz']}'"); + $value['access_id']=authcode($value['access_id'],'DECODE',$value['bz'])?authcode($value['access_id'],'DECODE',$value['bz']):$value['access_id']; + if(!$value['cloudname']) $value['cloudname']=$cloud['name'].':'.($value['bucket']?$value['bucket']:cutstr($value['access_id'], 4, '')); + if($value['bucket']) $value['bucket'].='/'; + $data=array( + 'id'=>$value['id'], + 'fid'=>md5($cloud['bz'].':'.$value['id'].':'.$value['bucket']), + 'pfid'=>0, + 'fname'=>$value['cloudname'], + 'ficon'=>'dzz/images/default/system/'.$cloud['bz'].'.png', + 'bz'=>$cloud['bz'].':'.$value['id'].':', + 'path'=>$cloud['bz'].':'.$value['id'].':'.$value['bucket'], + 'type'=>'storage', + 'fsperm'=>$value['bucket']?'0':perm_FolderSPerm::flagPower($cloud['bz'].'_root'), + 'perm'=>perm_binPerm::getGroupPower('all'), + 'flag'=>$cloud['bz'], + 'iconview'=>1, + 'disp'=>'0', + ); + + return $data; + } + public function fetch_all_by_id($ids){ + $data=array(); + foreach($ids as $id){ + if($value=self::fetch_by_id($id)) $data[$value['fid']]=$value; + } + return $data; + } + public function delete_by_id($id){ + //删除此应用的快捷方式 + $return=array(); + $data=parent::fetch($id); + if(parent::delete($id)){ + $return['msg']='success'; + //C::t('source_shortcut')->delete_by_bz($data['bz'].':'.$id.':',true);//删除快捷方式; + //删除图片缓存文件 + $imgcache=getglobal('setting/attachdir').'./imgcache/'.$data['bz'].'/'.$id.'/'; + removedirectory($imgcache); + } + return $return; + } + public function delete_by_uid($uid){ + if(!$uid) return 0; + foreach(DB::fetch_all("select id from %t where uid=%d",array($this->_table,$uid)) as $value){ + self::delete_by_id($value['id']); + } + return true; + } + public function delete_by_bz($bz){ + foreach(DB::fetch_all("select id from %t where bz=%s",array($this->_table,$bz)) as $value){ + self::delete_by_id($value['id']); + } + } +} + +?> diff --git a/core/class/table/table_cron.php b/core/class/table/table_cron.php new file mode 100644 index 0000000..0e8c0d0 --- /dev/null +++ b/core/class/table/table_cron.php @@ -0,0 +1,39 @@ +_table = 'cron'; + $this->_pk = 'cronid'; + + parent::__construct(); + } + + public function fetch_nextrun($timestamp) { + $timestamp = intval($timestamp); + return DB::fetch_first('SELECT * FROM '.DB::table($this->_table)." WHERE available>'0' AND nextrun<='$timestamp' ORDER BY nextrun LIMIT 1"); + } + + public function fetch_nextcron() { + return DB::fetch_first('SELECT * FROM '.DB::table($this->_table)." WHERE available>'0' ORDER BY nextrun LIMIT 1"); + } + + public function get_cronid_by_filename($filename) { + return DB::result_first('SELECT cronid FROM '.DB::table($this->_table)." WHERE filename='$filename'"); + } + +} + +?> diff --git a/core/class/table/table_district.php b/core/class/table/table_district.php new file mode 100644 index 0000000..a3b9bb7 --- /dev/null +++ b/core/class/table/table_district.php @@ -0,0 +1,41 @@ +_table = 'district'; + $this->_pk = 'id'; + + parent::__construct(); + } + + public function fetch_all_by_upid($upid, $order = null, $sort = 'DESC') { + $upid = is_array($upid) ? array_map('intval', (array)$upid) : dintval($upid); + if($upid !== null) { + $ordersql = $order !== null && !empty($order) ? ' ORDER BY '.DB::order($order, $sort) : ''; + return DB::fetch_all('SELECT * FROM %t WHERE '.DB::field('upid', $upid)." $ordersql", array($this->_table), $this->_pk); + } + return array(); + } + + public function fetch_all_by_name($name) { + if(!empty($name)) { + return DB::fetch_all('SELECT * FROM %t WHERE '.DB::field('name', $name), array($this->_table)); + } + return array(); + } + +} + +?> diff --git a/core/class/table/table_document.php b/core/class/table/table_document.php new file mode 100644 index 0000000..1f38c5f --- /dev/null +++ b/core/class/table/table_document.php @@ -0,0 +1,127 @@ +_table = 'document'; + $this->_pk = 'did'; + /* $this->_pre_cache_key = 'document_'; + $this->_cache_ttl = 0;*/ + + parent::__construct(); + } + + public function copy_by_did($did,$area='',$areaid=0,$fid=0){ //复制文档 + global $_G; + if(!$data=self::fetch($did)) return false; + unset($data['did']); + $data['version']=1; + $data['uid']=$_G['uid']; + $data['username']=$_G['username']; + $data['dateline']=TIMESTAMP; + if($area) $data['area']=$area; + if($areaid) $data['areaid']=$areaid; + if($fid) $data['fid']=$fid; + + if($data['did']=parent::insert($data,1)){ + $newest=array(); + $i=0; + foreach(DB::fetch_all("select * from %t where did=%d order by version",array('document_reversion',$did)) as $value){ + $attachs=array(); + + unset($value['revid']); + $value['did']=$data['did']; + $value['dateline']=TIMESTAMP; + $value['uid']=$_G['uid']; + $value['username']=$_G['username']; + $value['version']-=$i; + if($value['attachs']) $attachs=explode(',',$value['attachs']); + $attachs[]=$value['aid']; + if(C::t('document_reversion')->insert_by_parent($value)){ + C::t('attachment')->addcopy_by_aid($attachs); + $newest=$value; + }else{ + $i++; + } + } + if($newest){ + parent::update($data['did'],array('version'=>$newest['version'],'aid'=>$newest['aid'])); + return $data['did']; + }else{ + parent::delete($data['did']); + return false; + } + } + return false; + } + public function insert($arr,$attachs=array(),$area='',$areaid=0,$new=0){ //插入 + if(!$arr['did']){//首次插入 + $setarr=$arr; + $setarr['version']=1; + $setarr['area']=$area; + $setarr['areaid']=$areaid; + $setarr['dateline']=TIMESTAMP; + $arr['did']=parent::insert($setarr,1); + } + + $arr['attachs']=$attachs; + + //插入版本库 + $verarr=array('did'=>$arr['did'], + 'aid'=>$arr['aid'], + 'uid'=>$arr['uid'], + 'username'=>$arr['username'], + 'attachs'=>$attachs + ); + if($re=C::t('document_reversion')->insert($verarr,$new)){ + $setarr=array('version'=>$re['version'], + 'uid'=>$arr['uid'], + 'username'=>$arr['username'], + 'aid'=>$arr['aid'] + ); + parent::update($re['did'],$setarr); + } + return $arr['did']; + } + public function fetch_by_did($did){ + if(!$data=self::fetch($did)) return false; + $attach=C::t('attachment')->fetch($data['aid']); + return array_merge($attach,$data); + } + public function delete_by_did($did,$force=false){ + if(!$data=self::fetch($did)) return false; + if($force || $data['isdelete']){ + //删除版本 + C::t('document_reversion')->delete_by_did($did); + //删除评论 + C::t('comment')->delete_by_id_idtype($did,'document'); + return parent::delete($did); + }else{ + return parent::update($did,array('isdelete'=>TIMESTAMP)); + } + } + //获取最新的10条附件。 + public function fetch_all_by_areaid($areaid,$area='project',$limit='10'){ + global $_G; + $data=array(); + foreach(DB::fetch_all("select * from %t where areaid=%d and area=%s limit $limit",array($this->_table,$areaid,$area)) as $value){ + $attach=C::t('attachment')->fetch($value['aid']); + $data[$value['qid']]=array_merge($value,$attach); + } + return $data; + } +} + +?> diff --git a/core/class/table/table_document_event.php b/core/class/table/table_document_event.php new file mode 100644 index 0000000..65f2e9e --- /dev/null +++ b/core/class/table/table_document_event.php @@ -0,0 +1,54 @@ +_table = 'document_event'; + $this->_pk = 'eid'; + + parent::__construct(); + } + + public function delete_by_did($dids){ + if(!is_array($dids)) $dids=array($dids); + return DB::delete($this->_table,"did IN (".dimplode($dids).")"); + } + + public function fetch_all_by_did($did){ + $data=array(); + foreach(DB::fetch_all("select * from %t where did = %d order by dateline",array($this->_table,$did)) as $value){ + switch($value['action']){ + case 'create': + $value['faction']=lang('create_document'); + break; + case 'reversion': + $value['faction']=lang('edit_document'); + break; + case 'edit': + $value['faction']=lang('edit_document'); + break; + case 'delete': + $value['faction']=lang('delete_document'); + break; + case 'rename': + $value['faction']=lang('rename_document'); + break; + } + $data[]=$value; + } + } +} + +?> diff --git a/core/class/table/table_document_reversion.php b/core/class/table/table_document_reversion.php new file mode 100644 index 0000000..4c73986 --- /dev/null +++ b/core/class/table/table_document_reversion.php @@ -0,0 +1,199 @@ +_table = 'document_reversion'; + $this->_pk = 'revid'; + + parent::__construct(); + } + public function fetch_by_revid($revid){ + global $_G; + if(!$data=self::fetch($revid)) return false; + $attach=C::t('attachment')->fetch($data['aid']); + return array_merge($attach,$data); + } + public function reversion($did,$version,$uid,$username){ //使用此版本 + $newest=DB::fetch_first("select * from %t where did=%d order by version DESC limit 1",array($this->_table,$did)); + if($version==$newest['version']) return false;//已经是最新版了 + if($oversion=DB::fetch_first("select * from %t where did=%d and version=%d",array($this->_table,$did,$version))){ + unset($oversion['revid']); + $oversion['version']=$newest['version']+1; + $oversion['uid']=$uid; + $oversion['did']=$did; + $oversion['username']=$username; + $oversion['dateline']=TIMESTAMP; + if($oversion['revid']=parent::insert($oversion,1)){ + //插入事件 + $event=array('did'=>$did, + 'action'=>'reversion', + 'uid'=>$uid, + 'username'=>$username, + 'dateline'=>TIMESTAMP, + + ); + C::t('document_event')->insert($event); + + //更新附件的copys + $addids=array(); + if($oversion['attachs']) $addids=explode(',',$oversion['attachs']); + $addids[]=$oversion['aid']; + C::t('attachment')->addcopy_by_aid($addids); + //更新主文档表 + $setarr=array('version'=>$oversion['version'], + 'uid'=>$oversion['uid'], + 'username'=>$oversion['username'], + 'aid'=>$oversion['aid'] + ); + C::t('document')->update($did,$setarr); + } + return $oversion['version']; + } + return false; + } + public function insert_by_parent($arr){ + return parent::insert($arr,1); + } + public function insert($arr,$new){ + //先获取最新版本,没有的话新插入 + $newest=array(); + if($newest=DB::fetch_first("select * from %t where did=%d order by version DESC limit 1",array($this->_table,$arr['did']))){ + if($new){ + $arr['version']=$newest['version']+1; + $arr['dateline']=TIMESTAMP; + $attachs=array(); + if($arr['attachs']) { + $attachs=$arr['attachs']; + $arr['attachs']=implode(',',$attachs); + }else{ + $arr['attachs']=''; + } + if($arr['revid']=parent::insert($arr,1)){ + $attachs[]=$arr['aid']; + C::t('attachment')->addcopy_by_aid($attachs); + //插入事件 + $event=array('did'=>$arr['did'], + 'action'=>'edit', + 'uid'=>$arr['uid'], + 'username'=>$arr['username'], + 'dateline'=>TIMESTAMP + ); + C::t('document_event')->insert($event); + } + }else{ + $oldattachs=$newest['attachs']?explode(',',$newest['attachs']):array(); + $oldattachs[]=$newest['aid']; + + $attachs=array(); + if($arr['attachs']) { + $attachs=$arr['attachs']; + $arr['attachs']=implode(',',$arr['attachs']); + }else{ + $arr['attachs']=''; + } + $attachs[]=$arr['aid']; + if(parent::update($newest['revid'],$arr)){ + $arr['version']=$newest['version']; + $arr['revid']=$newest['revid']; + $delaids=array_diff($oldattachs,$attachs); + C::t('attachment')->addcopy_by_aid($delaids,-1); + $insertaids=array_diff($attachs,$oldattachs); + C::t('attachment')->addcopy_by_aid($insertaids); + } + } + }else{ + $arr['version']=1; + $arr['dateline']=TIMESTAMP; + $attachs=array(); + if($arr['attachs']) { + $attachs=$arr['attachs']; + $arr['attachs']=implode(',',$arr['attachs']); + }else{ + $arr['attachs']=''; + } + if($arr['revid']=parent::insert($arr,1)){ + $attachs[]=$arr['aid']; + C::t('attachment')->addcopy_by_aid($attachs); + //插入事件 + $event=array('did'=>$arr['did'], + 'action'=>'create', + 'uid'=>$arr['uid'], + 'username'=>$arr['username'], + 'dateline'=>TIMESTAMP + ); + C::t('document_event')->insert($event); + } + } + if($arr['revid']) return $arr; + else return false; + } + public function delete_by_version($did,$version){ + $vers=self::fetch_all_by_did($did); + self::delete($vers[$version]['revid']); + unset($vers[$version]); + $vers1=array(); + $vers=array_values(array_reverse($vers)); + foreach($vers as $key=> $value){ + $value['version']=$key+1; + parent::update($value['revid'],array('version'=>$value['version'])); + } + //更新主文档表 + if($value['version']>0){ + $setarr=array('version'=>$value['version'], + 'uid'=>$value['uid'], + 'username'=>$value['username'], + 'aid'=>$value['aid'] + ); + C::t('document')->update($did,$setarr); + return $value['version']; + }else{ + return false; + } + } + public function delete($revid){ + $data=parent::fetch($revid); + $attachs=array(); + if($data['attachs']) $attachs=explode(',',$data['attachs']); + $attachs[]=$data['aid']; + foreach($attachs as $aid){ + C::t('attachment')->delete_by_aid($aid); + } + return parent::delete($revid); + } + public function delete_by_did($dids){ + if(!is_array($dids)) $dids=array($dids); + $attachs=array(); + foreach(DB::fetch_all("select revid,aid,attachs from %t where did IN (%n) ",array($this->_table,$dids)) as $value){ + if($value['attachs']) $attachs=array_merge($attachs,explode(',',$value['attachs'])); + $attachs[]=$value['aid']; + $revids[]=$value['revid']; + } + foreach($attachs as $aid){ + C::t('attachment')->delete_by_aid($aid); + } + return parent::delete($revids); + } + public function fetch_all_by_did($did){ + $data=array(); + foreach(DB::fetch_all("select * from %t where did= %d order by version DESC",array($this->_table,$did)) as $value){ + $attach=C::t('attachment')->fetch($value['aid']); + $data[$value['version']]=array_merge($value,$attach); + } + return $data; + } +} + +?> diff --git a/core/class/table/table_failedlogin.php b/core/class/table/table_failedlogin.php new file mode 100644 index 0000000..6ca2ee5 --- /dev/null +++ b/core/class/table/table_failedlogin.php @@ -0,0 +1,38 @@ +_table = 'failedlogin'; + $this->_pk = ''; + + parent::__construct(); + } + + public function fetch_username($ip='', $username='') { + return DB::fetch_first("SELECT * FROM %t WHERE ip=%s AND username=%s", array($this->_table, $ip, $username)); + } + public function fetch_ip($ip='',$username='') { + return DB::fetch_first("SELECT * FROM %t WHERE ip=%s AND username = %s", array($this->_table, $ip,$username)); + } + + public function delete_old($time) { + DB::query("DELETE FROM %t WHERE lastupdate<%d", array($this->_table, TIMESTAMP - intval($time)), 'UNBUFFERED'); + } + + public function update_failed($ip='', $username='') { + DB::query("UPDATE %t SET count=count+1, lastupdate=%d WHERE ip=%s AND username = %s", array($this->_table, TIMESTAMP, $ip,$username)); + } + +} diff --git a/core/class/table/table_folder.php b/core/class/table/table_folder.php new file mode 100644 index 0000000..09d3966 --- /dev/null +++ b/core/class/table/table_folder.php @@ -0,0 +1,600 @@ +_table = 'folder'; + $this->_pk = 'fid'; + $this->_pre_cache_key = 'folder_'; + $this->_cache_ttl = 60 * 60; + parent::__construct(); + } + + public function update($fid, $data,$applytosub=false) + { + if (isset($data['perm'])) { + $perm = intval($data['perm']); + $data['perm_inherit'] = perm_check::getPerm1($fid, '', 0, $perm); + } + if ($ret = parent::update($fid, $data)) { + if (!empty($data['perm_inherit'])) {//如果更新权限的话,需要单独处理子目录的继承权限 + $this->set_newperm_by_pfid($fid,$data['perm_inherit'],$applytosub); + $indexdata = array('fid'=>$fid); + Hook::listen('changepermafter_updateindex',$indexdata); + /*$power = new perm_binPerm($perm); + if ($power->isPower('flag')) {//不继承,更新下级继承权限 + $subfids = array(); + foreach (DB::fetch_all("select p.fid from %t p LEFT JOIN %t f ON p.fid=f.fid where p.pathkey regexp %s and f.perm='0'", array('resources_path', 'folder', '^_'.$fid.'_.+')) as $value) { + $subfids[] = $value['fid']; + } + if ($subfids) parent::update($subfids, array('perm_inherit' => $perm)); + }*/ + } + } + return $ret; + } + //更改权限修改下级,$force==true,强制修改所有下级目录权限为继承(perm值设置为0) + public function set_newperm_by_pfid($pfid,$perm,$force=false){ + $pfid = intval($pfid); + foreach(DB::fetch_all("select fid,perm from %t where pfid = %d",array($this->_table,$pfid)) as $v){ + if(!$force && $v['perm']>0){ + continue; + }else{ + parent::update($v['fid'],array('perm'=>0,'perm_inherit'=>$perm)); + $indexdata = array('fid'=>$v['fid']); + Hook::listen('changepermafter_updateindex',$indexdata); + $this->set_newperm_by_pfid($v['fid'],$perm,$force); + } + } + return true; + } + public function update_by_pfids($pfids,$setarr){ + if(!is_array($pfids)) $pfids = (array)$pfids; + $fids = array(); + foreach(DB::fetch_all("select fid from %t where pfid in(%n)",array($this->_table,$pfids)) as $v){ + $fids[] = $v['fid']; + } + foreach($fids as $v){ + self::update($v,$setarr); + } + return true; + } + + //更改继承权限 + public function update_perm_inherit_by_fid($fids) + { + if (!is_array($fids)) $fids = (array)$fids; + foreach ($fids as $value) { + $perm_inherit = perm_check::getPerm1($value); + parent::update($value,array('perm_inherit' => $perm_inherit)); + } + } + + public function insert($data, $appid = 0) + { + if (empty($data)) { + return false; + } + if ($path['fid'] = parent::insert($data, 1)) { + $perm_inherit = perm_check::getPerm1($path['fid']); + parent::update($path['fid'], array('perm_inherit' => $perm_inherit)); + if ($data['pfid']) { + if (!$pdata = C::t('resources_path')->fetch_pathby_pfid($data['pfid'], true)) { + //根据fid生成path和pathkey + $pdata = self::create_pathinfo_by_fid($data['pfid'], $appid); + } + if (!$pdata) { + return array('error' => lang('failure_newfolder')); + } + $path['path'] = $pdata['path'] . $data['fname'] . "/"; + $path['pathkey'] = ($pdata['pathkey']) ? $pdata['pathkey'] . '-_' . $path['fid'] . '_' : '_' . $path['fid'] . '_'; + } else { + if ($appid) { + $path['path'] = "dzz:app_" . $appid . ":" . $data['fname'] . "/"; + } else { + $path['path'] = ($data['gid']) ? "dzz:gid_" . $data['gid'] . ":" . $data['fname'] . "/" : "dzz:uid_" . $data['uid'] . ":" . $data['fname'] . "/"; + } + $path['pathkey'] = '_' . $path['fid'] . '_'; + } + C::t('resources_path')->insert($path); + self::check_sub_by_flag($path['fid'],$data['flag']); + return $path['fid']; + } + return false; + } + public function check_sub_by_flag($pfid,$flag){//检查这个目录是否含有子目录,有就创建 + $subids=C::t('folder_sub')->fetch_all_by_flag($flag); + foreach($subids as $value){ + $params=array( + 'flag'=>$value['flag'], + 'fsperm'=>$value['fsperm'], + 'allow_exts'=>$value['allow_exts'], + 'iconview'=>$value['iconview'], + 'disp'=>$value['disp'] + ); + IO::CreateFolder($pfid, $value['fname'], $value['perm'], $params,'newcopy',true); + } + return true; + } + public function get_folder_pathinfo_by_fid($fid, $folderarr = array(), $i = 0) + { + if (!$folderinfo = parent::fetch($fid)) return; + + array_unshift($folderarr, array('fname' => $folderinfo['fname'], 'fid' => $folderinfo['fid'], 'gid' => $folderinfo['gid'], 'uid' => $folderinfo['uid'])); + + if ($folderinfo['pfid'] > 0 && $i < 100) { + $i++; + $folderarr = self::get_folder_pathinfo_by_fid($folderinfo['pfid'], $folderarr, $i); + } + return $folderarr; + } + + //根据fid生成path和pathkey + public function create_pathinfo_by_fid($fid, $appid = 0) + { + $patharr = array(); + if (!$pathdata = self::get_folder_pathinfo_by_fid($fid)) return $patharr; + $pathprefix = ($appid) ? "dzz:app_" . $appid . ":" : ''; + $path = ''; + $pathkey = ''; + foreach ($pathdata as $v) { + $path .= $v['fname'] . '/'; + $pathkey .= '_' . $v['fid'] . '_-'; + } + if (!$pathprefix) { + $pathprefix = ($v['gid']) ? "dzz:gid_" . $v['gid'] . ":" : "dzz:uid_" . $v['uid'] . ":"; + } + $patharr['path'] = $pathprefix . $path; + $patharr['pathkey'] = substr($pathkey, 0, -1); + return $patharr; + } + + public function check_home_by_uid($uid = '') + { + global $_G; + if (!$uid) $uid = $_G['uid']; + else $uid = intval($uid); + return DB::fetch_first("select f.*,p.path from %t f left join %t p on f.fid = p.fid where f.uid = %d and f.flag = %s", array($this->_table, 'resources_path', $uid, 'home')); + + } + + //查询个人文档目录以及路径 + public function fetch_home_by_uid($uid = '') + { + global $_G; + if (!$uid) $uid = $_G['uid']; + else $uid = intval($uid); + if ($return = DB::fetch_first("select f.*,p.path from %t f left join %t p on f.fid = p.fid where f.uid = %d and f.flag = %s", array($this->_table, 'resources_path', $uid, 'home'))) { + return $return; + } else { + $root = array( + 'pfid' => 0, + 'uid' => $uid, + 'username' => $_G['username'], + 'perm' => 0, + 'fname' => lang('explorer_user_root_dirname'), + 'flag' => 'home', + 'innav' => 1, + 'fsperm' => perm_FolderSPerm::flagPower('home') + ); + if ($rootfid = DB::result_first("select fid from " . DB::table('folder') . " where uid='{$uid}' and flag='home' ")) { + C::t('folder')->update($rootfid, array('fname' => $root['fname'], 'isdelete' => 0, 'pfid' => 0, 'fsperm' => $root['fsperm'], 'perm' => $root['perm'])); + } else { + $rootfid = C::t('folder')->insert($root); + C::t('folder')->update_perm_inherit_by_fid($rootfid); + } + $root['fid'] = $rootfid; + $root['path'] = C::t('resources_path')->fetch_pathby_pfid($rootfid); + return $root; + } + } + + //依文件名查询顶级目录 + public function fetch_topby_fname($fname) + { + $fid = DB::result_first("select fid from %t where fname = %s and pfid = 0", array($this->_table, $fname)); + return self::fetch_by_fid($fid); + } + + //返回一条数据及附件表数据 + public function fetch_by_fid($fid, $gid = '') + { + global $_G; + $fid = intval($fid); + if (!$data = self::fetch($fid)) array('error' => lang('file_not_exist')); + //获取目录的附加信息 + if($attr=C::t('folder_attr')->fetch_all_by_fid($fid)){ + $data=array_merge($data,$attr); + } + $data['title'] = $data['fname']; + //统计文件数 + if ($data['gid'] > 0) {//如果是群组 + //文件数 + $data['iconum'] = DB::result_first("select COUNT(*) from " . DB::table('resources') . " where pfid='{$fid}' and gid='{$gid}' and isdelete<1"); + //文件夹数 + $data['foldernum'] = DB::result_first("select COUNT(*) from " . DB::table('resources') . " where pfid='{$fid}' and gid='{$gid}' and type='folder' and isdelete<1"); + } else { + //文件数 + $data['iconum'] = DB::result_first("select COUNT(*) from " . DB::table('resources') . " where pfid='{$fid}' and isdelete < 1"); + //文件夹数 + $data['foldernum'] = DB::result_first("select COUNT(*) from " . DB::table('resources') . " where pfid='{$fid}' and type='folder' and isdelete < 1"); + } + $data['perm'] = perm_check::getPerm($fid); + $data['perm1'] = $data['perm_inherit']; + if ($data['gid'] > 0) { + $data['isadmin'] = $data['ismoderator'] = C::t('organization_admin')->is_admin_by_orgid($data['gid'], $_G['uid']); + $permtitle = perm_binPerm::getGroupTitleByPower($data['perm1']); + if (file_exists('dzz/images/default/system/folder-' . $permtitle['flag'] . '.png')) { + $data['icon'] = './dzz/images/default/system/folder-' . $permtitle['flag'] . '.png'; + } else { + $data['icon'] = './dzz/images/default/system/folder-read.png'; + } + } + $data['realpath'] = C::t('resources_path')->fetch_pathby_pfid($fid); + $data['relativepath'] = preg_replace('/dzz:(.+?):/', '', $data['realpath']); + $data['path'] = $data['fid']; + $data['oid'] = $data['fid']; + $data['bz'] = ''; + Hook::listen('filter_folder_fid', $data);//数据过滤挂载点 + return $data; + } + + //过滤文件名称 + public function name_filter($name) + { + return str_replace(array('/', '\\', ':', '*', '?', '<', '>', '|', '"', "\n"), '', $name); + } + + public function getFolderName($name, $pfid, $fid) + { + static $i = 0; + $name = self::name_filter($name); + //echo("select COUNT(*) from ".DB::table('folder')." where fname='{$name}' and pfid='{$pfid}'"); + if (DB::result_first("select COUNT(*) from %t where fname=%s and pfid=%d and fid != %d and isdelete<1", array('folder', $name, $pfid, $fid))) { + $name = preg_replace("/\(\d+\)/i", '', $name) . '(' . ($i + 1) . ')'; + $i += 1; + return self::getFolderName($name, $pfid, $fid); + } else { + return $name; + } + } + + //更改文件夹名称 + public function rename_by_fid($fid, $name) + { + if (!$folder = parent::fetch($fid)) return false; + //如果文件夹有对应的rid + if ($rid = C::t('resources')->fetch_rid_by_fid($fid)) { + $return = C::t('resources')->rename_by_rid($rid); + if ($return['error']) { + return false; + } else { + return true; + } + } else { + $name = self::getFolderName($name, $folder['pfid'], $fid); + //更改路径表数据 + if (C::t('resources_path')->update_path_by_fid($fid, $name)) { + //增加统计数 + $statisdata = array( + 'uid' => getglobal('uid'), + 'edits' => 1, + 'editdateline' => TIMESTAMP + ); + C::t('resources_statis')->add_statis_by_fid($fid, $statisdata); + //更改folder数据 + return parent::update($fid, array('fname' => $name)); + } else { + return false; + } + } + + } + + //查询组织id + public function fetch_gid_by_fid($fid, $i = 0) + { + + if (!$folder = parent::fetch($fid)) return 0; + if ($folder['flag'] == 'organization') return $folder['gid']; + elseif ($folder['pfid'] > 0) { + $i++; + if ($i > 100) { + return $folder['gid']; + } + return self::fetch_gid_by_fid($folder['pfid'], $i); + } + } + + //查询路径 + public function fetch_path_by_fid($fid, $fids = array()) + { + if (!$folder = parent::fetch($fid)) return; + $fids[] = $folder['fid']; + if ($folder['pfid'] > 0) { + $fids = self::fetch_path_by_fid($folder['pfid'], $fids); + } + return $fids; + } + + /* + 此函数不会删除 $fid对应的 rid数据,正常调用是作为C::t('resources')->deletesourcedata()的内部调用; + 如果单独调用,请注意这个fid应该没有对应的rid; + 我的网盘 应用主目录 群组和部门主目录 都是没有对应的rid的特殊目录; + */ + public function delete_by_fid($fid, $force = false) + { //清空目录 + $folder = self::fetch($fid); + //默认只允许删除文件夹和群组根目录,暂时不允许删除应用根目录 + if (!$force && $folder['flag'] =='app') { + return false; + } + //判断删除权限 + /* if (!perm_check::checkperm_container($fid, 'delete')) { + return array('error' => lang('no_privilege')); + }*/ + $rids = array(); + $isdelrids = array(); + $nodelrids = array(); + //获取当前文件夹包含的删除状态数据,及非删除状态数据 + foreach (DB::fetch_all("select rid,oid,isdelete from %t where pfid = %d", array('resources', $fid, $fid)) as $v) { + if ($v['isdelete'] > 0) { + $isdelrids[] = $v['rid']; + } else { + $nodelrids[] = $v['rid']; + } + $rids[] = $v['rid']; + } + $delrids = array(); + if (!$force) {//如果非强制彻底删除,只删除删除状态项 + $delrids = $isdelrids; + } else {//如果是强制删除,删除所有文件,包括非删除状态和删除状态文件 + $delrids = $rids; + //获取当前目录中在回收站中的数据 + foreach (DB::fetch_all("select rid from %t where pfid = %d", array('resources_recyle', $fid)) as $v) { + $delrids[] = $v['rid']; + } + } + //执行删除 + foreach ($delrids as $value) { + C::t('resources')->delete_by_rid($value, $force); + } + //如果当前目录是非删除状态或者下级有不能彻底删除文件(未删除文件),则跳过当前目录删除,只清空回收站表数据 + if (!$force && count($nodelrids) > 0) { + return 2; + } + return self::delete($fid); + } + + //删除目录 + public function delete($fid) + { + //删除路径表数据 + C::t('resources_path')->delete_by_fid($fid); + //删除文件夹属性表数据 + C::t('folder_attr')->delete_by_fid($fid); + //删除文件夹动态(只限于文件夹) + C::t('resources_event')->delete_by_pfid_and_notrid($fid); + return parent::delete($fid); + } + + public function fetch_all_default_by_uid($uid) + { + return DB::fetch_all("SELECT * FROM %t WHERE `default`!= '' and uid=%d ", array($this->_table, $uid), 'fid'); + } + + public function fetch_typefid_by_uid($uid) + { + $data = array(); + foreach (DB::fetch_all("SELECT * FROM %t WHERE `flag`!= 'folder' and uid='{$uid}' and gid<1 ", array($this->_table), 'fid') as $value) { + $data[$value['flag']] = $value['fid']; + } + return $data; + } + + public function fetch_all_by_pfid($pfid, $count) + { + global $_G; + $wheresql = 'pfid = %d and isdelete<1'; + if ($folder = C::t('folder')->fetch_by_fid($pfid)) { + $where1 = array(); + if (!$this->noperm && $folder['gid'] > 0) { + $folder['perm'] = perm_check::getPerm($folder['fid']); + + if ($folder['perm'] > 0) { + if (perm_binPerm::havePower('read1', $folder['perm'])) { + $where1[] = "uid ='{$_G[uid]}'"; + } + if (perm_binPerm::havePower('read2', $folder['perm'])) { + $where1[] = "uid!='{$_G[uid]}'"; + } + } + if ($where1) $wheresql .= " and (" . implode(' OR ', $where1) . ")"; + else $wheresql .= " and 0"; + } + } + if ($count) return DB::result_first("SELECT COUNT(*) FROM %t WHERE $wheresql", array($this->_table, $pfid)); + else return DB::fetch_all("SELECT * FROM %t WHERE $wheresql", array($this->_table, $pfid), 'fid'); + } + + public function fetch_folderinfo_by_gid($gid) + {//查询群组目录及文件基本信息 + $gid = intval($gid); + if ($info = DB::fetch_first("select f.*,p.path from %t f left join %t p on f.fid = p.fid where gid = %d and flag = %s", array($this->_table, 'resources_path', $gid, 'organization'))) { + return $info; + } + return false; + } + + public function fetch_fid_by_flag($flag) + { + $uid = getglobal('uid'); + return DB::result_first("select fid from %t where uid = %d and flag = %s", array($this->_table, $uid, $flag)); + } + + public function fetch_fid_by_flags($flags) + { + if (!is_array($flags)) $flags = (array)$flags; + $fids = array(); + foreach (DB::fetch_all("select fid from %t where flag in(%n)", array($this->_table, $flags)) as $v) { + $fids[] = $v['fid']; + } + return $fids; + } + + public function fetch_folderinfo_by_fid($fid) + {//查询群组目录及文件基本信息 + $fid = intval($fid); + if (!$folderinfo = self::fetch($fid)) { + return false; + } + $pathinfo = C::t('resources_path')->fetch_pathby_pfid($fid, true); + $info = array_merge($folderinfo, $pathinfo); + return $info; + + } + + //获取文件夹权限 + public function fetch_perm_by_fid($fid) + { + $perms = DB::fetch_first("select perm,perm_inherit from %t where fid = %d", array($this->_table, $fid)); + if ($perms['perm']) { + return $perms['perm']; + } else { + return $perms['perm_inherit']; + } + } + + public function fetch_folder_by_pfid($pfid, $field = array()) + {//查询群组目录及文件夹基本信息 + global $_G; + $fielddata = '*'; + if (!empty($field)) { + $fielddata = implode(',', $field); + } + $pfid = intval($pfid); + $infoarr = array(); + if ($folder = C::t('folder')->fetch($pfid)) { + $where1 = array(); + if (!$this->noperm && $folder['gid'] > 0) { + if (perm_check::checkperm_Container($folder['fid'], 'read2')) { + $where1[] = "1"; + } elseif (perm_check::checkperm_Container($folder['fid'], 'read1')) { + $where1[] = "uid='{$_G[uid]}'"; + } + $where1 = array_filter($where1); + if (!empty($where1)) $temp[] = "(" . implode(' OR ', $where1) . ")"; + else $temp[] = "0"; + } else { + $temp[] = " uid='{$_G[uid]}'"; + } + $where[] = '(' . implode(' and ', $temp) . ')'; + unset($temp); + } + $wheresql = "where pfid = %d and flag != %s and "; + if ($where) $wheresql .= implode(' AND ', $where); + else return false; + $infoarr = DB::fetch_all("select $fielddata from %t $wheresql and isdelete < 1 order by + convert(fname,UNSIGNED)" . + ",SUBSTRING_INDEX(fname,'-',1)" . + ",convert(replace(replace(SUBSTRING_INDEX(fname,'-',2),SUBSTRING_INDEX(fname,'-',1),''),'-','') , UNSIGNED) " . + ",convert(replace(replace(SUBSTRING_INDEX(fname,'-',3),SUBSTRING_INDEX(fname,'-',2),''),'-','') , UNSIGNED) ", array($this->_table, $pfid, 'organization')); + return $infoarr; + } + + //查询子文件夹fid + public function fetch_fid_by_pfid($pfid) + { + global $_G; + $pfid = intval($pfid); + $infoarr = array(); + if ($folder = C::t('folder')->fetch($pfid)) { + $where1 = array(); + if (!$this->noperm && $folder['gid'] > 0) { + $folder['perm'] = perm_check::getPerm($folder['fid']); + + if ($folder['perm'] > 0) { + if (perm_binPerm::havePower('read2', $folder['perm'])) { + $where1[] = "1"; + } elseif (perm_binPerm::havePower('read1', $folder['perm'])) { + $where1[] = "uid='{$_G[uid]}'"; + } + } + $where1 = array_filter($where1); + if (!empty($where1)) $temp[] = "(" . implode(' OR ', $where1) . ")"; + else $temp[] = "0"; + } else { + $temp[] = " uid='{$_G[uid]}'"; + } + $where[] = '(' . implode(' and ', $temp) . ')'; + unset($temp); + } + $wheresql = "where pfid = %d and "; + if ($where) $wheresql .= implode(' AND ', $where); + else return false; + $infoarr = DB::fetch_all("select fid from %t $wheresql", array($this->_table, $pfid)); + + return $infoarr; + } + + /* //查询所有有权限文件夹 + public function fetch_all_fid() + { + global $_G; + $uid = $_G['uid']; + $fids = array(); + //个人根目录 + $personfid = DB::result_first("select fid from %t where uid = %d and flag = %s", array($this->_table, $uid, 'home')); + $fids[] = $personfid; + foreach ($this->fetch_all_folderfid_by_pfid($personfid) as $v) { + $fids[] = $v; + } + //群组部门顶级目录 + $orgs = C::t('organization')->fetch_all_orgid(); + $orgids = $orgs['orgids']; + $fidarr = DB::fetch_all("select fid from %t where orgid in(%n)", array('organization', $orgids)); + + //群组目录及下级所有目录fid + foreach ($fidarr as $v) { + $fids[] = $v['fid']; + foreach ($this->fetch_all_folderfid_by_pfid($v['fid']) as $val) { + $fids[] = $val; + } + } + return $fids; + + }*/ + + + //查询目录下所有文件夹的fid + public function fetch_all_folderfid_by_pfid($pfid) + { + static $fids = array(); + foreach ($this->fetch_fid_by_pfid($pfid) as $v) { + $fids[] = $v['fid']; + $this->fetch_fid_by_pfid($v['fid']); + } + return $fids; + } + + //获取目录的所有上级目录 + public function fetch_all_parent_by_fid($fid, $ret = array()) + { + if (!$folder = parent::fetch($fid)) { + return $ret; + } + $ret[] = $folder; + if ($folder['pfid'] > 0) { + $ret = self::fetch_all_parent_by_fid($folder['pfid'], $ret); + } + return $ret; + } + +} \ No newline at end of file diff --git a/core/class/table/table_folder_attr.php b/core/class/table/table_folder_attr.php new file mode 100644 index 0000000..ae425c5 --- /dev/null +++ b/core/class/table/table_folder_attr.php @@ -0,0 +1,129 @@ +_table = 'folder_attr'; + $this->_pk = 'id'; + $this->_pre_cache_key = 'folder_attr_'; + $this->_cache_ttl = 60*60; + //$this->noperm = (getglobal('appGreenChannel'))?getglobal('appGreenChannel'):false; + parent::__construct(); + } + public function delete_by_id($id){ + if(!$data=parent::fetch($id)) return false; + if($ret=parent::delete($id)){ + if($data['skey']=='icon' && $data['svalue']>0){ + C::t('attachment')->delete_by_aid($data['svalue']); + } + } + return $ret; + } + public function update($id,$setarr){ + if(!$data=parent::fetch($id)) return false; + if($ret=parent::update($id,$setarr)){ + if($setarr['skey']=='icon'){ + if($data['svalue']) C::t('attachment')->delete_by_aid($data['svalue']); + if($setarr['svalue']) C::t('attachment')->addcopy_by_aid($setarr['svalue']); + } + } + return $ret; + } + public function insert($setarr){ + if($id=DB::result_first("select id from %t where fid=%d and skey=%s",array($this->_table,$setarr['fid'],$setarr['skey']))){ + if($setarr['skey']=='icon'){ + $o=parent::fetch($id); + } + $ret=parent::update($id,$setarr); + }else{ + $id=parent::insert($setarr,1); + } + //处理图标 + if($id && $setarr['skey']=='icon'){ + if($o['svalue']) C::t('attachment')->delete_by_aid($o['svalue']); + if($setarr['svalue']) C::t('attachment')->addcopy_by_aid($setarr['svalue']); + } + return $id; + } + public function insert_data_by_fid($fid,$skeyarr){//插入文件夹设置值 + foreach($skeyarr as $key=>$value){ + $setarr=array( + 'fid'=>$fid, + 'skey'=>$key, + 'svalue'=>$value + ); + self::insert($setarr); + } + return true; + } + public function update_by_fid($fid,$skeyarr){//更新文件设置 + foreach($skeyarr as $key=>$value){ + $setarr=array( + 'fid'=>$fid, + 'skey'=>$key, + 'svalue'=>$value, + ); + self::insert($setarr); + } + return true; + } + public function update_by_skey_fid($fid,$skey,$val){ + $setarr=array( + 'fid'=>$fid, + 'skey'=>$skey, + 'svalue'=>$val, + ); + return self::insert($searr); + + } + public function insert_by_skey_fid($fid,$skey,$val){ + $setarr = array( + 'fid'=>$fid, + 'skey'=>$skey, + 'svalue'=>$val + ); + return self::insert($setarr); + } + public function fetch_by_skey_fid($fid,$skey){ //获取文件夹某项设置值 + return DB::result_first("select svalue from %t where fid=%d and skey=%s",array($this->_table,$fid,$skey)); + } + public function delete_by_field_fid($fid,$skeys){ //删除文件夹某项设置值 + $skeys=(array)$skeys; + $i=0; + foreach(DB::fetch_all("select id from %t where fid=%d and skeys IN (%n)",array($this->_table,$fid,$skeys)) as $value){ + if(self::delete_by_id($value['id'])) $i++; + } + return $i; + } + public function delete_by_fid($fid){ //删除设置 + $fid=(array)$fid; + $i=0; + foreach(DB::fetch_all("select id from %t where fid=%d",array($this->_table,$fid)) as $value){ + if(self::delete_by_id($value['id'])) $i++; + } + return $i; + } + //获取当前文件夹所有附属信息 + public function fetch_all_folder_setting_by_fid($fid){ + $settings = array(); + foreach(DB::fetch_all("select * from %t where fid = %d",array($this->_table,$fid)) as $v){ + $settings[$v['skey']] = $v['svalue']; + } + return $settings; + } + //获取当前文件夹所有附属信息 + public function fetch_all_by_fid($fid){ + $settings = array(); + foreach(DB::fetch_all("select * from %t where fid = %d",array($this->_table,$fid)) as $v){ + if($v['skey']=='icon'){ + $v['svalue']=C::t('attachment')->getThumbByAid($value['svalue']); + } + $settings[$v['skey']] = $v['svalue']; + } + return $settings; + } +} \ No newline at end of file diff --git a/core/class/table/table_folder_default.php b/core/class/table/table_folder_default.php new file mode 100644 index 0000000..d6e6dd0 --- /dev/null +++ b/core/class/table/table_folder_default.php @@ -0,0 +1,39 @@ +_table = 'folder_default'; + $this->_pk = 'fid'; + $this->_pre_cache_key = 'folder_default_'; + $this->_cache_ttl = 0; + parent::__construct(); + } + public function fetch_all(){ + if(($data=$this->fetch_cache('all'))===false){ + $data=DB::fetch_all("SELECT * FROM %t WHERE 1 ORDER BY display", array($this->_table)); + } + return $data; + } + public function fetch_all_by_default(){ + if(($data=$this->fetch_cache('all'))===false){ + $data=DB::fetch_all("SELECT * FROM %t WHERE `default`!='' ORDER BY display DESC", array($this->_table)); + } + return $data; + } + +} + +?> diff --git a/core/class/table/table_folder_flag.php b/core/class/table/table_folder_flag.php new file mode 100644 index 0000000..b990742 --- /dev/null +++ b/core/class/table/table_folder_flag.php @@ -0,0 +1,32 @@ +_table = 'folder_flag'; + $this->_pk = 'flag'; + $this->_pre_cache_key = 'folder_flag_'; + $this->_cache_ttl = 60*60; + parent::__construct(); + } + public function insert_by_flag($setarr){ + if(!$flag=$setarr['flag']) return false; + + if(parent::fetch($flag)){ + unset($setarr['flag']); + if($ret=parent::update($flag,$setarr)){ + unset($setarr['system']); + foreach(DB::fetch_all("select fid from %t where flag=%s",array('folder',$flag)) as $value){ + C::t('folder')->update($value['fid'],$setarr); + } + } + return $ret; + }else{ + return parent::insert($setarr,1); + } + } +} \ No newline at end of file diff --git a/core/class/table/table_folder_flag_formlist.php b/core/class/table/table_folder_flag_formlist.php new file mode 100644 index 0000000..678dd34 --- /dev/null +++ b/core/class/table/table_folder_flag_formlist.php @@ -0,0 +1,48 @@ +_table = 'folder_flag_formlist'; + $this->_pk = 'flag'; + $this->_pre_cache_key = 'folder_flag_formlist_'; + $this->_cache_ttl = 60*60; + parent::__construct(); + } + public function insert_by_flag($setarr){ + if(!$flag=$setarr['flag']) return false; + if(parent::fetch($flag)){ + unset($setarr['flag']); + parent::update($flag,$setarr); + }else{ + return parent::insert($setarr,1); + } + } + public function fetch_by_flag($flag,$system=0){ + if(!$data=parent::fetch($flag)){ + $data['formlist']='name,fsize,ftype,fdateline'; + } + $flags=explode(',',$data['formlist']); + $temp=array(); + foreach(C::t('form_setting')->fetch_all($flags) as $value){ + if($system){ + if($system==1){ + if($value['system']) $temp[$value['flag']]=$value; + }elseif($system==2){ + if(!$value['system']) $temp[$value['flag']]=$value; + } + }else{ + $temp[$value['flag']]=$value; + } + } + //排序 + foreach($flags as $v){ + $ret[$v]=$temp[$v]; + } + return $ret; + } +} \ No newline at end of file diff --git a/core/class/table/table_folder_sub.php b/core/class/table/table_folder_sub.php new file mode 100644 index 0000000..a55ba1f --- /dev/null +++ b/core/class/table/table_folder_sub.php @@ -0,0 +1,52 @@ +_table = 'folder_sub'; + $this->_pk = 'subid'; + $this->_pre_cache_key = 'folder_sub_'; + $this->_cache_ttl = 60*60; + parent::__construct(); + } + //获取默认子目录信息 + public function fetch_all_by_flag($flag){ + return DB::fetch_all("select * from %t where pflag=%s",array($this->_table,$flag)); + } + public function insert_by_subid($setarr){ + if(!$flag=$setarr['flag']) return false; + if(self::check_flag($setarr['flag'])) return false; + if(empty($setarr['fname'])) return false; + return parent::insert($setarr,1); + + } + public function update($subid,$setarr){ + if($ret=parent::update($subid,$setarr)){ + $flag=$setarr['flag']; + $allow_exts=isset($setarr['allow_exts'])?$setarr['allow_exts']:null; + unset($setarr['pflag']); + unset($setarr['flag']); + unset($setarr['allow_exts']); + foreach(DB::fetch_all("select fid from %t where flag=%s",array('folder',$flag)) as $value){ + C::t('folder')->update($value['fid'],$setarr); + if(isset($allow_exts)){ + $arr=array( + 'fid'=>$value['fid'], + 'skey'=>'allow_exts', + 'svalue'=>$allow_exts + ); + C::t('folder_attr')->insert($arr); + } + } + } + } + //检查flag不能和主flag同名 + public function check_flag($flag){ + return DB::result_first("select COUNT(*) from %t where flag=%s",array('folder_flag',$flag)); + } + +} \ No newline at end of file diff --git a/core/class/table/table_form_setting.php b/core/class/table/table_form_setting.php new file mode 100644 index 0000000..8770d33 --- /dev/null +++ b/core/class/table/table_form_setting.php @@ -0,0 +1,131 @@ +_table = 'form_setting'; + $this->_pk = 'flag'; + parent::__construct(); + } + + public function fetch($flag){ + $data=parent::fetch($flag); + + if($data['options']) $data['options']=unserialize($data['options']); + if($data['extra']) $data['extra']=unserialize($data['extra']); + + if($data['extra']['mindate']){ + $data['extra']['mindate'] = dgmdate($data['extra']['mindate'],$data['extra']['dateformat']); + } + if($data['extra']['maxdate']){ + $data['extra']['maxdate'] = dgmdate($data['extra']['maxdate'],$data['extra']['dateformat']); + } + + return $data; + } + //插入表单数据; + public function insert_by_flag($flag,$form){ + if(empty($flag)) return false; + if(!in_array($form['type'],$this->type)) return false; + if(empty($form['labelname'])) return false; + + $setarr['labelname']=getstr($form['labelname'],60); + $setarr['required']=intval($form['required']); + $setarr['multiple']=intval($form['multiple']); + $setarr['type']=$form['type']; + $setarr['disp']=intval($form['disp']); + $setarr['system']=intval($form['system']); + switch($form['type']){ + case 'input':case 'textarea': + $setarr['length']=intval($form['length']); + $setarr['regex']=trim($form['regex']); + $extra=array( + 'hint'=>getstr($form['hint']), + ); + $setarr['extra'] = serialize($extra); + break; + case 'select': + $setarr['options']=is_array($form['options'])?serialize($form['options']):''; + $setarr['multiple']=0; + break; + case 'multiselect': + $setarr['options']=is_array($form['options'])?serialize($form['options']):''; + break; + case 'time': + $setarr['multiple']=0; + $extra=array( + 'maxdate'=>$form['maxdate']?strtotime($form['maxdate']):0, + 'mindate'=>$form['mindate']?strtotime($form['mindate']):0, + 'dateformat'=>trim($form['dateformat']) + ); + $setarr['extra'] = serialize($extra); + break; + + case 'user': + + break; + + } + if(parent::fetch($flag)){ + parent::update($flag,$setarr); + $setarr['flag'] = $flag; + }else{ + $setarr['flag'] = $flag; + parent::insert($setarr,1); + } + $setarr['extra']=unserialize($setarr['extra']); + if($setarr['extra']['mindate']){ + $setarr['extra']['mindate'] = dgmdate($setarr['extra']['mindate'],$setarr['extra']['dateformat']); + } + if($setarr['extra']['maxdate']){ + $setarr['extra']['maxdate'] = dgmdate($setarr['extra']['maxdate'],$setarr['extra']['dateformat']); + } + $setarr['options']=unserialize($setarr['options']); + return $setarr; + } + + /*获取所有表单项*/ + public function fetch_all($flags=array()){ + $data=array(); + $sql = 1; + $param = array($this->_table); + if($flags){ + $sql.=" and flag in (%n)"; + $param[] = $flags; + } + foreach(DB::fetch_all("select * from %t where $sql order by disp",$param) as $value){ + if($value['extra']){ + $value['extra']=unserialize($value['extra']); + if($value['extra']['mindate']){ + $value['extra']['mindate'] = dgmdate($value['extra']['mindate'],$value['extra']['dateformat']); + } + if($value['extra']['maxdate']){ + $value['extra']['maxdate'] = dgmdate($value['extra']['maxdate'],$value['extra']['dateformat']); + } + + } + if($value['options']){ + $value['options']=unserialize($value['options']); + } + $data[]=$value; + } + return $data; + } + public function delete_by_flag($flag){ + return parent::delete($flag); + } + +} \ No newline at end of file diff --git a/core/class/table/table_hooks.php b/core/class/table/table_hooks.php new file mode 100644 index 0000000..47b9416 --- /dev/null +++ b/core/class/table/table_hooks.php @@ -0,0 +1,86 @@ +_table = 'hooks'; + $this->_pk = 'id'; + $this->_pre_cache_key = 'hooks_'; + $this->_cache_ttl =0; + parent::__construct(); + } + + public function update_by_appid($appid,$setarr){ + if(empty($appid)) return false; + $appid=(array)$appid; + $ids=array(); + foreach(DB::fetch_all("select id from %t where app_market_id IN(%n)",array('hooks',$appid)) as $value){ + $ids[]=$value['id']; + } + if($ret=parent::update($ids,$setarr)){ + self::clear_cache_tags(); + } + return $ret; + } + public function delete_by_appid($appid){ + if(empty($appid)) return false; + $appid=(array)$appid; + $ids=array(); + foreach(DB::fetch_all("select id from %t where app_market_id IN(%n)",array('hooks',$appid)) as $value){ + $ids[]=$value['id']; + } + if($ret=parent::delete($ids)){ + self::clear_cache_tags(); + } + return $ret; + } + public function insert_by_appid($appid,$hooks,$attributes=array()){ + if(!$appid) return false; + $ret=0; + foreach($hooks as $name =>$addons){ + $priority=0; + $description=""; + if( $attributes ){//xml导入时附带其他属性,如优先级,描述等信息 + if(isset($attributes[$name]["_attributes"]) ) { + $priority = isset($attributes[$name]["_attributes"]["priority"])?$attributes[$name]["_attributes"]["priority"]:$priority; + $description = isset($attributes[$name]["_attributes"]["description"])?$attributes[$name]["_attributes"]["description"]:$description; + } + } + + if($hid=DB::result_first("select id from %t where name=%s and addons=%s",array($this->_table,$name,$addons))){ + if(parent::update($hid,array('app_market_id'=>$appid,'priority'=>$priority,'description'=>$description,'status'=>0))){ + $ret+=1; + } + }else{ + $data=array( + 'app_market_id'=>$appid, + 'name'=>$name, + 'priority'=>$priority, + 'description'=>$description, + 'type'=>'1', + 'addons'=>$addons, + 'status'=>0 + ); + if(parent::insert($data,1,1)){ + $ret+=1; + } + } + } + if($ret) self::clear_cache_tags(); + return $ret; + } + public function clear_cache_tags(){ + @unlink(DZZ_ROOT.'./data/cache/tags.php'); + } +} +?> diff --git a/core/class/table/table_icon.php b/core/class/table/table_icon.php new file mode 100644 index 0000000..c1807e0 --- /dev/null +++ b/core/class/table/table_icon.php @@ -0,0 +1,64 @@ +_table = 'icon'; + $this->_pk = 'did'; + $this->_pre_cache_key = 'icon_'; + $this->_cache_ttl = 60*60; + parent::__construct(); + } + public function delete_by_did($did){ + global $_G; + $icon=self::fetch($did); + @unlink($_G['setting']['attachdir'].$icon['pic']); + return self::delete($did); + } + public function update_copys_by_did($did,$ceof=1){ + global $_G; + if($icon=self::fetch($did)){ + if($icon['check']<2 && ($icon['copys']+$ceof)<1 && $icon['check']<1){ + @unlink($_G['setting']['attachdir'].$icon['pic']); + C::t('icon')->delete($did); + }else{ + C::t('icon')->update($did,array('copys'=>$icon['copys']+$ceof)); + } + } + } + public function fetch_by_link($link){//根据连接判断icon + + $data = array(); + $parse_url=parse_url($link); + $host=$parse_url['host']; + $host=preg_replace("/^www./",'',$host);//strstr('.',$host); + if($_SERVER['HTTP_HOST']==$host || $_SERVER['HTTP_HOST']=='www.'.$host) $host='localhost'; + foreach(DB::fetch_all("select * from %t where domain=%s order by disp DESC,dateline DESC",array($this->_table,$host)) as $value){ + if($value['reg']){ + if(preg_match("/^\/.+?\/\w+$/i",$value['reg']) && preg_match($value['reg'],$link)){ + return $value; + }elseif(strpos($link,$value['reg'])!==false){ + return $value; + } + }else{ + $data[]=$value; + } + } + return $data?$data[0]:array(); + } + + +} + +?> diff --git a/core/class/table/table_iconview.php b/core/class/table/table_iconview.php new file mode 100644 index 0000000..9a5ceaa --- /dev/null +++ b/core/class/table/table_iconview.php @@ -0,0 +1,28 @@ +_table = 'iconview'; + $this->_pk = 'id'; + /*$this->_pre_cache_key = 'iconview_'; + $this->_cache_ttl = 0;*/ + parent::__construct(); + } + public function fetch_all(){ + return DB::fetch_all("select * from %t where 1",array($this->_table),'id'); + } +} + +?> diff --git a/core/class/table/table_imagetype.php b/core/class/table/table_imagetype.php new file mode 100644 index 0000000..e33c818 --- /dev/null +++ b/core/class/table/table_imagetype.php @@ -0,0 +1,33 @@ +_table = 'imagetype'; + $this->_pk = 'typeid'; + + parent::__construct(); + } + + public function fetch_all_by_type($type, $available = null) { + $available = $available !== null ? ($available ? ' AND available=1' : ' AND available=0') : ''; + return DB::fetch_all("SELECT * FROM %t WHERE type=%s %i ORDER BY displayorder", array($this->_table, $type, $available)); + } + + public function fetch_all_available() { + return DB::fetch_all("SELECT * FROM %t WHERE available=1", array($this->_table)); + } + + public function count_by_name($type, $name) { + return DB::result_first("SELECT COUNT(*) FROM %t WHERE type=%s AND name=%s", array($this->_table, $type, $name)); + } + +} + +?> \ No newline at end of file diff --git a/core/class/table/table_local_router.php b/core/class/table/table_local_router.php new file mode 100644 index 0000000..c3d207c --- /dev/null +++ b/core/class/table/table_local_router.php @@ -0,0 +1,102 @@ +_table = 'local_router'; + $this->_pk = 'routerid'; + //$this->_pre_cache_key = 'local_router_'; + //$this->_cache_ttl = 0; + parent::__construct(); + } + public function fetch_by_routerid($routerid){ + $data=self::fetch($routerid); + $data['router']=unserialize($data['router']); + $data['drouter']=self::getRouterDetail($data['router']); + return $data; + } + public function fetch_all_orderby_priority($available=false){ + $data=array(); + $where='1'; + if($available){ + $where.=' and `available`>0'; + } + foreach(DB::fetch_all("SELECT * FROM %t WHERE $where ORDER BY priority DESC ",array($this->_table)) as $value){ + $value['router']=unserialize($value['router']); + $value['drouter']=self::getRouterDetail($value['router']); + $data[$value['routerid']]=$value; + } + return $data; + } + public function getRouterDetail($router){ + $html=''; + foreach($router as $type =>$value){ + + switch($type){ + case 'exts': + if($value) $html.="文件后缀:".implode(',',$value); + else $html.="文件后缀:不限制"; + break; + case 'size': + $sizearr=array(); + if(is_numeric($value['lt'])) $sizearr[]="大于".formatsize($value['lt']*1024*1024); + if(is_numeric($value['gt'])) $sizearr[]="小于".formatsize($value['gt']*1024*1024); + if($sizearr) $html.='
文件大小:'.implode(' and ',$sizearr); + else $html.='
文件大小:不限制'; + break; + } + } + + return $html; + } + public function insert($setarr){ + $setarr['router']=serialize($setarr['router']); + return parent::insert($setarr,1); + } + public function update($routerid,$setarr){ + if($setarr['router']) $setarr['router']=serialize($setarr['router']); + return parent::update($routerid,$setarr); + } + public function delete_by_remoteid($remoteid){ + return DB::delete($this->_table,"remoteid='{$remoteid}'"); + } + //根据路由规则筛选出存储位置 + public function getRemoteId($data){ + $remoteid=0; + $guize=self::fetch_all_orderby_priority(true); + foreach($guize as $value){ + //没有此存储位置 + if(!$ldata = C::t('local_storage')->fetch($value['remoteid'])){ + continue; + }else{ + $available = DB::result_first("select available from %t where bz = %s", array('connect',$ldata['bz'])); + if($available <1) continue; + } + //云停用跳转 + if($available<1) continue; + if($value['router']['exts']){ + if(!in_array(strtolower($data['filetype']),$value['router']['exts'])) continue; + } + if(is_numeric($value['router']['size']['lt']) && $data['filesize']<$value['router']['size']['lt']*1024*1024) continue; + if(is_numeric($value['router']['size']['gt']) && $data['filesize']>$value['router']['size']['gt']*1024*1024) continue; + return $value['remoteid']; + } + + return $remoteid; + } +} + +?> diff --git a/core/class/table/table_local_storage.php b/core/class/table/table_local_storage.php new file mode 100644 index 0000000..76d7d1b --- /dev/null +++ b/core/class/table/table_local_storage.php @@ -0,0 +1,119 @@ +_table = 'local_storage'; + $this->_pk = 'remoteid'; + /*$this->_pre_cache_key = 'local_storage_'; + $this->_cache_ttl = 300;*/ + parent::__construct(); + } + + public function fetch_by_remoteid($remoteid){ + $remoteid=intval($remoteid); + if(!$data=self::fetch($remoteid)){ + return array(); + } + if($connect=C::t('connect')->fetch($data['bz'])){ + $data=array_merge($connect,$data); + } + if($data['dname'] && $data['did']){ + if($pan=C::t($data['dname'])->fetch($data['did'])) $data=array_merge($pan,$data); + } + return $data; + } + public function getBzByRemoteid($remoteid){ //通过remoteid获取bz,默认返回dzz + if(!($data=self::fetch_by_remoteid($remoteid))){ + return 'dzz'; + } + if($data['type']=='pan') $bz=$data['bz'].':'.$data['id'].':'.$data['root']; + elseif($data['type']=='storage') $bz=$data['bz'].':'.$data['id'].':'.$data['bucket']; + elseif($data['type']=='ftp') $bz=$data['bz'].':'.$data['id'].':'.$data['root']; + elseif($data['type']=='disk') $bz=$data['bz'].':'.$data['id'].':'.$data['root']; + else $bz='dzz'; + return $bz; + } + public function fetch_all_orderby_disp(){ + $data=array(); + foreach(DB::fetch_all("SELECT s.*,c.available FROM %t s LEFT JOIN %t c ON c.bz=s.bz WHERE 1 ORDER BY s.disp ",array($this->_table,'connect')) as $value){ + $data[$value['remoteid']]=$value; + } + return $data; + } + public function update_usesize_by_remoteid($remoteid,$ceof){ + if(!$remoteid) $remoteid=DB::result_first("select remoteid from %t where bz='dzz' limit 1",array($this->_table)); + $ceof=intval($ceof); + try{ + if($ceof>0){ + DB::query("update %t set usesize=usesize+%d where remoteid=%d",array($this->_table,$ceof,$remoteid)); + }else{ + DB::query("update %t set usesize=usesize-%d where remoteid=%d",array($this->_table,abs($ceof),$remoteid)); + } + $this->clear_cache($remoteid); + }catch(Exception $e){} + return true; + } + public function update_sizecount_by_remoteid($remoteid){ + if($arr=self::getQuota($remoteid)){ + self::update($remoteid,$arr); + return $arr; + } + return false; + } + + public function getQuota($remoteid){ + global $_G; + $data=self::fetch_by_remoteid($remoteid); + $return=array(); + if($data['type']=='local'){ + $return['usesize']=C::t('attachment')->getSizeByRemote($remoteid); + $return['totalsize']=disk_free_space($_G['setting']['attachdir']); + }elseif($data['type']=='pan'){ + $bz=$data['bz'].':'.$data['id'].':'; + $arr=IO::getQuota($bz); + $return['usesize']=C::t('attachment')->getSizeByRemote($remoteid); + if(is_numeric($arr['quota']) && is_numeric($arr['used'])) $return['totalsize']=($arr['quota'])-($arr['used']); + }elseif($data['type']=='storage'){ + $return['usesize']=C::t('attachment')->getSizeByRemote($remoteid); + $return['totalsize']=0; + }elseif($data['type']=='ftp'){ + $bz=$data['bz'].':'.$data['id'].':'; + $return['usesize']=C::t('attachment')->getSizeByRemote($remoteid); + $return['totalsize']=0; + }elseif($data['type']=='disk'){ + $bz=$data['bz'].':'.$data['id'].':'; + $return['usesize']=C::t('attachment')->getSizeByRemote($remoteid); + $return['totalsize']=disk_free_space($data['attachdir']); + }else{ + $return['usesize']=C::t('attachment')->getSizeByRemote($remoteid); + $return['totalsize']=0; + } + return $return; + } + public function delete_by_remoteid($remoteid){ + $data=self::fetch($remoteid); + if($data['bz']=='dzz') return array('error'=>'内置,不能删除'); + if(C::t('attachment')->getSizeByRemote($remoteid)>0) return array('error'=>'有文件未迁移,不能删除'); + C::t('local_router')->delete_by_remoteid($remoteid); + if($data['dname'] && $data['did']) C::t($data['dname'])->delete_by_id($data['did']);//删除链接 + return self::delete($remoteid); + } + public function getRemoteId(){ + return DB::result_first("select s.remoteid from ".DB::table('local_storage')." s LEFT JOIN ".DB::table('connect')." c ON s.bz=c.bz where c.available>0 order by s.isdefault DESC, s.disp ASC"); + } + +} + +?> diff --git a/core/class/table/table_mailcron.php b/core/class/table/table_mailcron.php new file mode 100644 index 0000000..cb41a54 --- /dev/null +++ b/core/class/table/table_mailcron.php @@ -0,0 +1,45 @@ +_table = 'mailcron'; + $this->_pk = 'cid'; + + parent::__construct(); + } + + public function delete_by_touid($touids) { + if(empty($touids)) { + return false; + } + return DB::query('DELETE FROM mc, mq USING %t AS mc, %t AS mq WHERE mc.'.DB::field('touid', $touids).' AND mc.cid=mq.cid', + array($this->_table, 'mailqueue'), false, true); + } + + public function fetch_all_by_email($email, $start, $limit) { + return DB::fetch_all('SELECT * FROM %t WHERE email=%s '.DB::limit($start, $limit), array($this->_table, $email)); + } + + public function fetch_all_by_touid($touid, $start, $limit) { + return DB::fetch_all('SELECT * FROM %t WHERE touid=%d '.DB::limit($start, $limit), array($this->_table, $touid)); + } + + public function fetch_all_by_sendtime($sendtime, $start, $limit) { + return DB::fetch_all('SELECT * FROM %t WHERE sendtime<=%d ORDER BY sendtime '.DB::limit($start, $limit), array($this->_table, $sendtime)); + } +} + +?> diff --git a/core/class/table/table_mailqueue.php b/core/class/table/table_mailqueue.php new file mode 100644 index 0000000..75f02a1 --- /dev/null +++ b/core/class/table/table_mailqueue.php @@ -0,0 +1,38 @@ +_table = 'mailqueue'; + $this->_pk = 'qid'; + + parent::__construct(); + } + + public function fetch_all_by_cid($cids) { + if(empty($cids)) { + return array(); + } + return DB::fetch_all('SELECT * FROM %t WHERE '.DB::field('cid', $cids), array($this->_table)); + } + + public function delete_by_cid($cids) { + if(empty($cids)) { + return false; + } + return DB::query('DELETE FROM %t WHERE '.DB::field('cid', $cids), array($this->_table)); + } +} + +?> diff --git a/core/class/table/table_notification.php b/core/class/table/table_notification.php new file mode 100644 index 0000000..afc4e22 --- /dev/null +++ b/core/class/table/table_notification.php @@ -0,0 +1,91 @@ +_table = 'notification'; + $this->_pk = 'id'; + + parent::__construct(); + } + + public function delete_clear($new, $days) { + $days = TIMESTAMP - intval($days) * 86400; + DB::query("DELETE FROM %t WHERE new=%d AND dateline<%d", array($this->_table, $new, $days)); + } + public function delete_by_type($type, $uid = 0) { + if(!$type) { + return; + } + $uid = $uid ? ' AND '.DB::field('uid', $uid) : ''; + return DB::query("DELETE FROM %t WHERE type=%s %i", array($this->_table, $type, $uid)); + } + + public function optimize() { + DB::query("OPTIMIZE TABLE %t", array($this->_table), true); + } + + public function fetch_by_fromid_uid($id, $idtype, $uid) { + return DB::fetch_first("SELECT * FROM %t WHERE from_id=%d AND from_idtype=%s AND uid=%d", array($this->_table, $id, $idtype, $uid)); + } + public function fetch_by_fromid_uid_type($id, $idtype, $uid,$type) { + return DB::fetch_first("SELECT * FROM %t WHERE from_id=%d AND from_idtype=%s AND uid=%d AND type=%s", array($this->_table, $id, $idtype, $uid,$type)); + } + + public function delete_by_id_uid($id, $uid) { + DB::query("DELETE FROM %t WHERE id=%d AND uid=%d", array($this->_table, $id, $uid)); + } + + public function delete_by_uid($uid) { + DB::query("DELETE FROM %t WHERE uid IN (%n) OR authorid IN (%n)", array($this->_table, $uid, $uid)); + } + + public function fetch_all_by_authorid_fromid($authorid, $fromid, $type) { + return DB::fetch_all("SELECT * FROM %t WHERE authorid=%d AND from_id=%d AND type=%s", array($this->_table, $authorid, $fromid, $type)); + } + + public function ignore($uid, $new = true, $from_num = true) { + $uid = intval($uid); + $update = array(); + if($new) { + $update['new'] = 0; + } + if($from_num) { + $update['from_num'] = 0; + } + $where = array('uid' => $uid, 'new' => 1); + + if($update) { + DB::update($this->_table, $update, $where); + } + } + + public function count_by_uid($uid, $new, $type = '') { + $new = intval($new); + $type = $type ? ' AND '.DB::field('type', $type) : ''; + + $new = $new != '-1' ? ' AND '.DB::field('new', $new) : ''; + return DB::result_first("SELECT COUNT(*) FROM %t WHERE uid=%d %i %i %i", array($this->_table, $uid, $new, $category, $type)); + } + + public function fetch_all_by_uid($uid, $new, $type, $start, $perpage) { + $new = intval($new); + $type = $type ? ' AND '.DB::field('type', $type) : ''; + + $new = $new != '-1' ? ' AND '.DB::field('new', $new) : ''; + return DB::fetch_all("SELECT * FROM %t WHERE uid=%d %i %i ORDER BY dateline DESC %i", array($this->_table, $uid, $new, $type, DB::limit($start, $perpage))); + } +} + +?> diff --git a/core/class/table/table_onlinetime.php b/core/class/table/table_onlinetime.php new file mode 100644 index 0000000..96c6927 --- /dev/null +++ b/core/class/table/table_onlinetime.php @@ -0,0 +1,37 @@ +_table = 'onlinetime'; + $this->_pk = 'uid'; + + parent::__construct(); + } + + public function update_onlinetime($uid, $total, $thismonth, $lastupdate) { + if(($uid = intval($uid))) { + DB::query("UPDATE ".DB::table('onlinetime')." + SET total=total+'$total', thismonth=thismonth+'$thismonth', lastupdate='".$lastupdate."' WHERE ".DB::field($this->_pk, $uid)); + return DB::affected_rows(); + } + return false; + } + + public function range_by_field($start = 0, $limit = 0, $orderby = '', $sort = '') { + $orderby = in_array($orderby, array('thismonth', 'total', 'lastupdate'), true) ? $orderby : ''; + return DB::fetch_all('SELECT * FROM '.DB::table($this->_table).($orderby ? ' WHERE '.$orderby.' >0 ORDER BY '.DB::order($orderby, $sort) : '').' '.DB::limit($start, $limit), null, $this->_pk); + } + + public function update_thismonth() { + return DB::update($this->_table, array('thismonth'=>0)); + } + +} + +?> \ No newline at end of file diff --git a/core/class/table/table_organization.php b/core/class/table/table_organization.php new file mode 100644 index 0000000..f71a094 --- /dev/null +++ b/core/class/table/table_organization.php @@ -0,0 +1,1065 @@ +_table = 'organization'; + $this->_pk = 'orgid'; + $this->_pre_cache_key = 'organization_'; + // $this->_cache_ttl = 60*60; + + parent::__construct(); + } + /*获取所有下级部门 + $count: >0 仅返回数量 + $type: -1:全部部门或群组;1:仅群组;0;仅机构或部门 + $forgid: 上级orgid,当$forgid=0时,获取所有一级 + */ + public function fetch_all_by_forgid($forgid, $count = 0, $type = 0) + { + if ($count) $sql = 'SELECT COUNT(*) FROM %t WHERE forgid= %d'; + else $sql = 'SELECT * FROM %t WHERE forgid= %d'; + $param = array($this->_table, $forgid); + if ($type > -1) { + $sql .= ' and `type`=%d'; + $param[] = $type; + } + if ($count) return DB::result_first($sql, $param); + return DB::fetch_all($sql . ' ORDER BY disp', $param, 'orgid'); + } + + /* + 获取用户参与的部门或群组信息 + $uid: 参与人,为空时为当前用户 + $type: -1:全部部门或群组;1:仅群组;0;仅机构或部门 + return array(); + */ + public function fetch_all_by_uid($uid,$type=-1){ + if(empty($uid)) $uid=getglobal('uid'); + if(!$uid) return array(); + if($orgids=C::t('organization_user')->fetch_orgids_by_uid($uid,$type)){ + parent::fetch_all($orgids); + } + return array(); + } + //插入数据 + public function insert($arr){ + if($orgid=parent::insert($arr)){ + if(intval($arr['aid'])){//如果有头像图片,增加copys + C::t('attachment')->add_by_aid(intval($arr['aid'])); + } + } + return $orgid; + } + + //查询机构群组信息 + public function fetch_all_orggroup($uid,$getmember = true) + { + global $_G; + $groups = array(); + if($_G['adminid'] == 1){ + $orgids = DB::fetch_all("select orgid from %t where `type`=%d and forgid = %d",array($this->_table,0,0)); + foreach($orgids as $v){ + $groups['org'][]= parent::fetch($v['orgid']); + } + }else{ + if ($uid) { + $orgids = C::t('organization_user')->fetch_org_by_uid($uid); + $orgids = array_unique($orgids); + $toporgids = array(); + foreach (parent::fetch_all($orgids) as $v) { + if ($v['type'] == 0) { + $patharr = explode('-', $v['pathkey']); + $toporgid = intval(str_replace('_', '', $patharr[0])); + if (in_array($toporgid, $toporgids)) { + continue; + } + $orginfo=parent::fetch($toporgid); + if (C::t('organization_admin')->chk_memberperm($toporgid, $uid) > 0) { + if($orginfo['syatemon'] == 1){ + if($getmember){ + $orginfo['usernum'] = C::t('organization_user')->fetch_num_by_toporgid($toporgid); + $orginfo['adminer'] = C::t('organization_admin')->fetch_adminer_by_orgid($toporgid); + } + $groups['org'][] = $orginfo; + } + //$orginfo = DB::fetch_first("select * from %t where `orgid` = %d and syatemon = %d ORDER BY disp", array($this->_table, $toporgid, 1)); + + } else { + if ($orginfo['syatemon'] == 1 && $orginfo['manageon'] == 1 && $orginfo['diron'] == 1) { + if($getmember){ + $orginfo['usernum'] = C::t('organization_user')->fetch_num_by_toporgid($toporgid); + $orginfo['adminer'] = C::t('organization_admin')->fetch_adminer_by_orgid($toporgid); + } + $groups['org'][] = $orginfo; + } + } + $toporgids[] = $toporgid; + } + } + + } + } + return $groups; + } + + public function fetch_group_by_uid($uid, $foreces = false) + {//查询自定义群组,$foreces=true为jstree加载内容,进行群组开启判断 + global $_G; + if (!$uid) return false; + $groups = array(); + $orgids = C::t('organization_user')->fetch_orgids_by_uid($uid,1); + foreach (DB::fetch_all("select * from %t where `orgid` IN(%n) order by disp", array($this->_table, $orgids)) as $orginfo) { + + if ($foreces) { + if ($orginfo['syatemon'] == 0) {//系统管理员关闭群组 + continue; + //如果是普通成员,判断群组是否关闭,暂时用diron来进行判断 + } elseif ($orginfo['diron'] == 0 && C::t('organization_admin')->chk_memberperm($orginfo['orgid'], $uid) == 0) {//管理员关闭群组,当前用户不具备管理员权限 + continue; + } + } + //jstree加载不需获取成员数和创建者 + if(!$foreces){ + $orginfo['usernum'] = C::t('organization_user')->fetch_usernums_by_orgid($orginfo['orgid']); + $orginfo['creater'] = C::t('organization_admin')->fetch_group_creater($orginfo['orgid']); + } + + if ($orginfo['aid'] > 0) { + //群组图 + $orginfo['imgs'] = 'index.php?mod=io&op=thumbnail&width=24&height=24&path=' . dzzencode('attach::' . $orginfo['aid']); + } + /* $contaions = C::t('resources')->get_contains_by_fid($orginfo['fid'],true); + $orginfo['ffsize'] = lang('property_info_size', array('fsize' => formatsize($contaions['size']), 'size' => $contaions['size'])); + $orginfo['contain'] = lang('property_info_contain', array('filenum' => $contaions['contain'][0], 'foldernum' => $contaions['contain'][1]));*/ + $groups[] = $orginfo; + } + return $groups; + } + + public function delete_by_orgid($orgid) + { + if (!$org = parent::fetch($orgid)) { + return array('error' => lang('remove_error_object_inexistence')); + } + if (self::fetch_all_by_forgid($org['orgid'], true) || ($org['fid'] && DB::result_first("select count(*) from %t where pfid = %d and isdelete < 1", array('resources', $org['fid'])))) { + return array('error' => lang('remove_error_check_the_content')); + } + //删除对应目录 + if ($org['fid']) { + C::t('folder')->delete_by_fid($org['fid'],true); + } + //删除对应事件 + C::t('resources_event')->delete_by_gid($orgid); + //删除对应用户 + C::t('organization_user')->delete_by_orgid($orgid); + //删除对应管理员 + C::t('organization_admin')->delete_by_orgid($orgid); + if (parent::delete($orgid)) { + if (intval($org['aid']) != 0) { + C::t('attachment')->addcopy_by_aid($org['aid'], -1); + } + if( $org["type"]==0){//非群主才同步 + self::syn_organization($org['orgid'],'delete'); + } + return $org; + } else { + return array('error' => lang('delete_error')); + } + } + + + //判断用户是否是该部门或机构下级成员 + public function ismember($orgid,$uid=0,$onlychild = false) + { + if(!$uid) $uid=getglobal('uid'); + $pathkey = '_' . $orgid . '_'; + $orgids = array(); + if($onlychild){ + $pathkey = $pathkey . '.+'; + }else{ + $pathkey = $pathkey . '.*'; + } + foreach (DB::fetch_all("select orgid from %t where pathkey regexp %s", array($this->_table, $pathkey)) as $v) { + $orgids[] = $v['orgid']; + } + if (DB::result_first("select count(*) from %t where uid = %d and orgid in (%n) ", array('organization_user', $uid, $orgids)) > 0) { + return true; + } + return false; + } + + //获取机构群组下级 + public function fetch_org_by_uidorgid($uid, $orgid) + { + + $resultarr = array(); + //如果该用户是当前部门普通成员则不获取下级机构信息,如果是下级机构成员或当前机构管理员则获取下级部门信息 + if (C::t('organization_admin')->chk_memberperm($orgid, $uid)) {//如果是管理员 + $resultarr = self::fetch_all_by_forgid($orgid,0,0); + + } elseif ($this->ismember($orgid,$uid,true)) {//如果是当前机构或部门下级的成员 + $orgids = C::t('organization_user')->fetch_orgids_by_uid($uid,0); + $pathkeyarr = DB::fetch_all("select pathkey from %t where orgid in (%n) ", array($this->_table, $orgids)); + $porgids = array(); + foreach ($pathkeyarr as $v) { + $vs = str_replace('_', '', $v['pathkey']); + $varr = explode('-', $vs); + $porgids = array_merge($porgids,$varr); + } + + $orgsarr = self::fetch_all_by_forgid($orgid,0,0); + $orgidarr = array(); + foreach ($orgsarr as $v) { + + if (!in_array($v['orgid'], $orgidarr) && in_array($v['orgid'], $porgids)) { + + if (C::t('organization_admin')->chk_memberperm($v['orgid'], $uid) > 0 && $v['syatemon'] == 1) { + $resultarr[] = $v; + } elseif ($v['syatemon'] && $v['manageon'] && $v['diron']) { + $resultarr[] = $v; + } + $orgidarr[] = $v['orgid']; + } + } + + } + //print_r($resultarr); + return $resultarr; + } + + //获取包含当前机构或部门包含下级的orgid + public function get_all_contaionchild_orgid($orgid, $uid) + { + $orgids = array(); + if (!$org = self::fetch($orgid)) { + return $orgids; + } + if ($org['type'] > 0) { + $orgids[] = $orgid; + return $orgids; + } + if (C::t('organization_admin')->chk_memberperm($orgid, $uid)) {//如果是管理员 + $orgids = self::get_childorg_by_orgid($orgid); + } elseif ($this->ismember($uid, $orgid,true)) {//如果不是管理员,判断是否是下级成员 + $orgidarrs = array(); + //获取当前用户所在的所有群组id + foreach (DB::fetch_all("select o.orgid,o.pathkey,o.manageon,o.diron from %t u left join %t o on o.orgid = u.orgid where u.uid = %d and o.type = 0", array('organization_user', 'organization', $uid)) as $v) { + $pathkey = $v['pathkey']; + $orgidarr = explode('-', str_replace('_', '', $pathkey)); + if (in_array($orgid, $orgidarr)) { + foreach ($orgidarr as $v) { + $orgidarrs[] = $v; + } + } + } + $orgids = array_unique($orgidarrs); + } + return $orgids; + } + + //获取当前部门或机构的下级 + public function get_childorg_by_orgid($orgid) + { + $orgidarr = array(); + if (!$orgid) return $orgidarr; + $pathkey = DB::result_first("select pathkey from %t where orgid = %d", array($this->_table, $orgid)); + $orgids = DB::fetch_all("select orgid from %t where pathkey regexp %s ", array($this->_table, '^' . $pathkey . '.*')); + foreach ($orgids as $v) { + $orgidarr[] = $v['orgid']; + } + return $orgidarr; + } + + //获取机构群组的上级id + public function fetch_parent_by_orgid($orgid,$onlyid=true) + { + $pathkey = DB::result_first("select pathkey from %t where orgid = %d", array($this->_table, $orgid)); + $path = str_replace('_', '', $pathkey); + $patharr = explode('-', $path); + if($onlyid){ + return $patharr; + }else{ + return parent::fetch_all($patharr); + } + } + + //将available修改为diron,后期将调整 + public function setFolderAvailableByOrgid($orgid, $available=0) + { + if (!$org = parent::fetch($orgid)) return false; + if ($available > 0 && $org['forgid'] > 0) {//上级没有开启目录共享,下级无法开启 + $parent = parent::fetch($org['forgid']); + if ($parent['diron'] < 1) return false; + } + if (parent::update($orgid, array('diron' => $available))) { + //self::setFolderByOrgid($orgid); + //include_once libfile('function/cache'); + //updatecache('organization'); + return true; + } + return false; + } + + //暂时将syatemon调整为manageon + public function setgroupByOrgid($orgid, $groupon=0) + { + if (!$org = parent::fetch($orgid)) return false; + /*if ($groupon > 0 && $org['forgid'] > 0) { + $toporgid = self::getTopOrgid($orgid); + $top = parent::fetch($toporgid); + if ($top['manageon'] < 1) return false; + }*/ + if (parent::update($orgid, array('manageon' => $groupon))) { + return true; + } + return false; + } + + public function setIndeskByOrgid($orgid, $indesk) + { + if (!$org = parent::fetch($orgid)) return false; + if ($indesk > 0) { + if ($org['available'] < 1) return false; + } + if (parent::update($orgid, array('indesk' => $indesk))) { + /*include_once libfile('function/cache'); + updatecache('organization');*/ + return true; + } + return false; + } + + public function setFolderByOrgid($orgid) + { + if (!$org = parent::fetch($orgid)) return false; + if ($org['forgid'] == 0) { + $pfid = 0; + } else { + $pfid = DB::result_first("select fid from " . DB::table($this->_table) . " where orgid='{$org['forgid']}'"); + } + + if ($fid = DB::result_first("select fid from " . DB::table('folder') . " where gid='{$orgid}' and flag='organization'")) { + if(C::t('folder')->rename_by_fid($fid,$org['orgname'])){ + self::update($orgid, array('fid' => $fid)); + } + } else { + $folder = array('fname' => C::t('folder')->getFolderName($org['orgname'],$pfid,$org['fid']), + 'pfid' => $pfid, + 'display' => $org['disp'], + 'flag' => 'organization', + 'gid' => $org['orgid'], + 'innav' => $org['available'], + 'uid' => getglobal('uid'), + 'username' => getglobal('username'), + 'perm' => perm_binPerm::getGroupPower('read') + ); + $fid = C::t('folder')->insert($folder, 0); + } + if ($fid) { + self::update($org['orgid'], array('fid' => $fid)); + return $fid; + } + return false; + } + + public function setDispByOrgid($orgid, $disp, $forgid = 0) + { + if (!$org = parent::fetch($orgid)) return false; + + if ($torg = DB::fetch_first("select disp,orgid from %t where forgid=%d and orgid!=%d order by disp limit %d,1", array($this->_table, $forgid, $orgid, $disp))) { + $disp = $torg['disp']; + + foreach (DB::fetch_all("select orgid,disp from %t where disp>%d and forgid=%d", array($this->_table, $disp, $forgid)) as $value) { + parent::update($value['orgid'],array('disp'=>$value['disp']+1)); + //self::wx_update($value['orgid']); + } + + } else { + $disp = DB::result_first("select max(disp) from %t where forgid=%d", array($this->_table, $forgid)) + 1; + } + if ($return = parent::update($orgid, array('disp' => $disp, 'forgid' => $forgid))) { + + if ($org['forgid'] != $forgid) { + //检查重名 + $orgname = self::get_uniqueName_by_forgid($forgid, $org['orgname'], $org['orgid']); + if ($orgname != $org['orgname']) {//有重名 + self::update_by_orgid($org['orgid'], array('orgname' => $orgname)); + } + //重新设置所有下级机构的共享目录 + if ($pathkey = self::setPathkeyByOrgid($orgid)) { + $like = '^' . $pathkey; + foreach (DB::fetch_all("select orgid from %t where pathkey REGEXP %s", array($this->_table, $like)) as $value) { + self::setFolderByOrgid($value['orgid']); + } + } + } + if ($disp > 10000) { + foreach (DB::fetch_all("select orgid ,disp from %t where forgid=%d", array($this->_table, $forgid)) as $value) { + parent::update($value['orgid'],array('disp'=>$value['disp']-9000)); + } + } + return $return; + } else { + return false; + } + } + + public function getDispByOrgid($borgid) + { + $data = parent::fetch($borgid); + $disp = $data['disp'] + 1; + // DB::query("update %t SET disp=disp+1 where disp>=%d and forgid=%d", array($this->_table, $disp, $data['forgid'])); + return $disp; + } + + public function chk_by_orgname($orgname,$type = 0,$forgid=0) + { + if (DB::result_first("select count(*) from %t where orgname = %s and `type` = %d and forgid = %d", array($this->_table, $orgname,$type,$forgid)) > 0) { + return false; + } + return true; + } + + public function insert_by_orgid($setarr, $synwx = 1) + { + $setarr['orgname'] = self::get_uniqueName_by_forgid($setarr['forgid'], $setarr['orgname']); + if ($setarr['orgid'] = parent::insert($setarr, true)) { + //self::setFolderByOrgid($org['orgid']); + //include_once libfile('function/cache'); + //updatecache('organization'); + $uid = getglobal('uid'); + $username = getglobal('username'); + $fid = self::setFolderByOrgid($setarr['orgid']);//添加对应群组目录,默认未启用 + //添加自定义群组时,添加对应创始人 + if ($setarr['type'] !=0) { + C::t('organization_user')->insert_by_orgid($setarr['orgid'],$uid); + C::t('organization_admin')->insert($uid, $setarr['orgid'], 2); + } + //添加对应动态 + $eventdata = array('groupname' => $setarr['orgname'], 'uid' => getglobal('uid'), 'username' => getglobal('username')); + C::t('resources_event')->addevent_by_pfid($fid, 'create_group', 'create', $eventdata, $setarr['orgid']); + self::setPathkeyByOrgid($setarr['orgid']); + return $setarr['orgid']; + } + return false; + } + + public function insert_by_forgid($setarr, $borgid) + { + if ($borgid) { + $setarr['disp'] = self::getDispByOrgid($borgid); + } + $setarr['orgname'] = self::get_uniqueName_by_forgid($setarr['forgid'], $setarr['orgname']); + if ($setarr['orgid'] = parent::insert($setarr, true)) { + self::setFolderByOrgid($setarr['orgid']); + //include_once libfile('function/cache'); + //updatecache('organization'); + if (isset($setarr['type']) && $setarr['type'] != 0) { + $uid = getglobal('uid'); + C::t('organization_admin')->insert($uid, $setarr['orgid'], 1); + } + + self::setPathkeyByOrgid($setarr['orgid']); + if(isset($setarr['type']) && $setarr['type'] == 0 ) self::syn_organization($setarr['orgid']); + return $setarr; + } + + return false; + } + + public function syn_organization( $data=array(),$type="update" ){ + if( $type=="update"){ + Hook::listen('syntoline_department',$data);//注册绑定到三方部门表 + }else if( $type=="delete"){ + Hook::listen('syntoline_department',$data,"del");//删除对应到三方部门表 + } + } + + public function update_by_orgid($orgid, $setarr, $synwx = 1) + { + if (!$org = self::fetch($orgid)) return false; + if (isset($setarr['orgname'])) { + $fid = $org['fid']; + $name = self::get_uniqueName_by_forgid($org['forgid'], getstr($setarr['orgname']), $orgid); + if (C::t('folder')->rename_by_fid($fid, $name)) { + if (parent::update($orgid, array('orgname' => $name))) { + $body_data = array('username' => getglobal('username'), 'oldname' => $org['orgname'], 'newname' => $name); + $event_body = 'update_group_name'; + C::t('resources_event')->addevent_by_pfid($org['fid'], $event_body, 'update_groupname', $body_data, $orgid, '', $org['orgname']);//记录事件 + if( $synwx && $org['type']==0) self::syn_organization($orgid); + } + unset($setarr['orgname']); + } + + } + + if (isset($setarr['perm']) && $setarr['perm']) { + $fid = $org['fid']; + C::t('folder')->update($fid, array('perm' => $setarr['perm'])); + unset($setarr['perm']); + } + if (isset($setarr['desc'])) { + $setarr['desc'] = htmlspecialchars($setarr['desc']); + } + if (empty($setarr)) return true; + if (parent::update($orgid, $setarr)) { + //处理图标copys数 + if(isset($setarr['aid'])){ + $oaid=intval($org['aid']); + $aid=intval($setarr['aid']); + if($oaid){ + C::t('attachment')->addcopy_by_aid($oaid,-1); + } + if($aid){ + C::t('attachment')->addcopy_by_aid($aid); + } + } + $org = array_merge($org, $setarr); + self::setFolderByOrgid($org['orgid']); + $body_data = array('username' => getglobal('username')); + $event_body = 'update_group_setting'; + C::t('resources_event')->addevent_by_pfid($org['fid'], $event_body, 'update_setting', $body_data, $orgid, '', $org['orgname']);//记录事件 + self::setPathkeyByOrgid($orgid); + if( $synwx && $org['type']==0 ) self::syn_organization($orgid); + return true; + } + return true; + } + + public function getTopOrgid($orgid) + { + include_once libfile('function/organization'); + $ids = self::fetch_parent_by_orgid($orgid); + return $ids[0]; + } + public function getUpOrgidTree($orgid,$pids=array()){ + global $_G; + if($org=C::t('organization')->fetch($orgid)){ + //$pids[]=$orgid; + array_unshift($pids,$orgid); + $pids=self::getUpOrgidTree($org['forgid'],$pids); + } + return ($pids); + } + + public function setPathkeyByOrgid($orgid, $force = 0) + { //设置此机构的pathkey的值,$force>0 重设此部门的pathkey + @set_time_limit(0); + if (!$org = parent::fetch($orgid)) return false; + if($org['type'] > 0){ + $pathkey = '_'.$orgid.'_'; + if (parent::update($org['orgid'], array('pathkey' => $pathkey))) return $pathkey; + return false; + }else{ + if ($force || empty($org['pathkey'])) {//没有pathkey, + // include_once libfile('function/organization'); + if($ids=self::getUpOrgidTree($org['orgid'])){ + $pathkey='_'.implode('_-_',$ids).'_'; + if( parent::update($org['orgid'],array('pathkey'=>$pathkey))) return $pathkey; + } + return false; + } + //设置所有子部门的pathkey; + if ($org['forgid'] && ($porg = parent::fetch($org['forgid']))) { + $npathkey = $porg['pathkey'] . '-' . '_' . $orgid . '_'; + } else { + $npathkey = '_' . $orgid . '_'; + } + if ($org['pathkey'] == $npathkey) return $npathkey; //没有改变; + $like = '^' . $org['pathkey']; + foreach(DB::fetch_all("select orgid,pathkey from %t where pathkey REGEXP %s", array($this->_table, $like)) as $value){ + parent::update($value['orgid'],array('pathkey'=>str_replace($org['pathkey'],$npathkey,$value['pathkey']))); + } + /*if (DB::query("update %t set pathkey=REPLACE(pathkey,%s,%s) where pathkey REGEXP %s", array($this->_table, $org['pathkey'], $npathkey, $like))) { + return $npathkey; + }*/ + } + } + + + public function wx_update($orgid) + { + global $_G; + if (!$this->_wxbind) return; + if (!$org = parent::fetch($orgid)) return false; + if ($org['type'] > 0) {//群主类型不同步至微信 + return false; + } + $wx = new qyWechat(array('appid' => $_G['setting']['CorpID'], 'appsecret' => $_G['setting']['CorpSecret'], 'agentid' => 0)); + $wd = array(); + if ($wxdepart = $wx->getDepartment()) { + foreach ($wxdepart['department'] as $value) { + $wd[$value['id']] = $value; + } + } else { + return false; + } + if ($org['forgid']) { + if (($forg = parent::fetch($org['forgid'])) && !$forg['worgid']) { + if ($worgid = self::wx_update($forg['orgid'])) { + $forg['worgid'] = $worgid; + } else { + return; + } + } + } + $parentid = ($org['forgid'] == 0 ? 1 : $forg['worgid']); + if ($org['worgid'] && $wd[$org['worgid']] && $parentid == $wd[$org['worgid']]['parentid']) {//更新机构信息 + $data = array("id" => $org['worgid']); + + if ($wd[$org['worgid']]['name'] != $org['orgname']) $data['name'] = $org['orgname']; + if ($wd[$org['worgid']]['parentid'] != $parentid) $data['parentid'] = $parentid; + if ($wd[$org['worgid']]['order'] != $org['order']) $data['order'] = $org['order']; + if ($data) $data['id'] = $org['worgid']; + if ($data) { + if (!$wx->updateDepartment($data)) { + $message = 'updateDepartment:errCode:' . $wx->errCode . ';errMsg:' . $wx->errMsg; + runlog('wxlog', $message); + return false; + } + } + return $org['worgid']; + + } else { + $data = array( + "name" => $org['orgname'], //部门名称 + "parentid" => $org['forgid'] == 0 ? 1 : $forg['worgid'], //父部门id + "order" => $org['disp'] + 1, //(非必须)在父部门中的次序。从1开始,数字越大排序越靠后 + ); + if ($ret = $wx->createDepartment($data)) { + parent::update($orgid, array('worgid' => $ret['id'])); + return $ret['id']; + } else { + if ($wx->errCode == '60008') {//部门的worgid不正确导致的问题 + foreach ($wd as $value) { + if ($value['name'] == $data['name'] && $value['parentid'] = $data['parentid']) { + C::t('organization')->update($org['orgid'], array('worgid' => $value['id'])); + return $value['id']; + } + } + } + $message = 'createDepartment:errCode:' . $wx->errCode . ';errMsg:' . $wx->errMsg; + runlog('wxlog', $message); + return false; + } + } + return false; + } + + public function getPathByOrgid($orgid,$space='-') + { + $ret = array(); + if ($org = parent::fetch($orgid)) { + $ids = explode('-', str_replace('_', '', $org['pathkey'])); + $arr = parent::fetch_all($ids); + foreach ($ids as $id) { + if ($arr[$id]) $ret[] = $arr[$id]['orgname']; + } + } + if($space) $ret=implode($space,$ret); + return $ret; + } + + //获取用户有权限的机构orgid + public function fetch_all_orgid() + { + global $_G; + $uid = $_G['uid']; + //获取当前用户参与的机构和群组 + $orgids = array(); + $orgids_admin = array(); + $orgids_member = array(); + $explorer_setting = get_resources_some_setting(); + if($_G['adminid'] == 1){ + $orgdatas = DB::fetch_all("select orgid,`type` from %t where 1", array('organization')); + }else{ + $orgdatas = DB::fetch_all("select u.orgid,o.`type` from %t u left join %t o on u.orgid=o.orgid where uid = %d", array('organization_user', 'organization', $uid)); + } + foreach ($orgdatas as $v) { + if (!$explorer_setting['grouponperm'] && $v['type'] == 1) { + continue; + } + if (!$explorer_setting['orgonperm'] && $v['type'] == 0) { + continue; + } + $orgids[] = $v['orgid']; + } + //获取对应权限的机构orgid + foreach ($orgids as $val) { + //当前机构或部门管理员,查询所有下级和上级 + if (C::t('organization_admin')->chk_memberperm($val, $uid)) { + $path = DB::result_first("select pathkey from %t where orgid = %d", array($this->_table, $val)); + $patharr = DB::fetch_all("select pathkey from %t where pathkey regexp %s and available = %d", array($this->_table, '^' . $path . '.*', 1)); + foreach ($patharr as $v) { + $pathstr = str_replace('_', '', $v['pathkey']); + if ($orgidarr = explode('-', $pathstr)) $orgids_admin = array_merge($orgids_admin, $orgidarr); + } + + } else {//当前部门成员查询所有上级机构 + $path = DB::result_first("select pathkey from %t where orgid = %d and available = %d and diron = %d", array($this->_table, $val, 1, 1)); + $pathstr = str_replace('_', '', $path); + if ($orgidarr = explode('-', $pathstr)) $orgids_member = array_merge($orgids_member, $orgidarr); + + } + } + $member_orgids = array(); + //判断参与群组的群组开启和文件开启 + foreach (DB::fetch_all('select manageon,diron,orgid from %t where orgid in(%n)', array($this->_table, $orgids_member)) as $v) { + if ($v['manageon'] && $v['diron']) { + $member_orgids[] = $v['orgid']; + } + } + return array('orgids' => array_unique(array_merge($orgids_admin, $member_orgids)), 'orgids_admin' => array_unique($orgids_admin), 'orgids_member' => array_unique(array_diff($member_orgids, $orgids_admin))); + } + + //获取用户管理的所有群组orgid + public function fetch_all_manage_orgid() + { + global $_G; + $uid = $_G['uid']; + $explorer_setting = get_resources_some_setting(); + $manageorgid = DB::fetch_all("select orgid from %t where uid = %d", array('organization_admin', $uid)); + $orgids = array(); + $orgarr = array(); + foreach ($manageorgid as $v) { + if (!in_array($v['orgid'], $orgarr)) { + $info = DB::fetch_first("select pathkey,type from %t where orgid = %d", array($this->_table, $v['orgid'])); + if (!$explorer_setting['grouponperm'] && $info['type'] == 1) { + continue; + } + if (!$explorer_setting['orgonperm'] && $info['type'] == 0) { + continue; + } + $pathkey = $info['pathkey']; + $orgidarr = DB::fetch_all("select orgid,orgname from %t where pathkey regexp %s ", array($this->_table, '^' . $pathkey . '.*')); + foreach ($orgidarr as $val) { + $orgids[$val['orgid']] = array('orgid' => $val['orgid'], 'orgname' => $val['orgname']); + $orgarr[] = $val['orgid']; + } + } + } + return $orgids; + } + + //我参与的所有群组和机构 + public function fetch_all_part_org() + { + $uid = getglobal('uid'); + $orgid = array(); + foreach (DB::fetch_all("select orgid from %t where uid = %d", array('organization_user', $uid)) as $v) { + $orgid[] = $v['orgid']; + } + $orgid = array_unique($orgid); + $explorer_setting = get_resources_some_setting(); + $orgarr = array(); + foreach (DB::fetch_all("select * from %t where orgid in(%n)", array($this->_table, $orgid)) as $v) { + if (!$explorer_setting['grouponperm'] && $v['type'] == 1) { + continue; + } + if (!$explorer_setting['orgonperm'] && $v['type'] == 0) { + continue; + } + $org = array('orgid' => $v['orgid'], 'orgname' => $v['orgname']); + $orgarr[] = $org; + } + return $orgarr; + } + + //获取群组类型 + public function get_grouptype_by_orgid($orgid) + { + if (!is_array($orgid)) { + return DB::result_first("select `type` from %t where orgid = %d", array($this->_table, $orgid)); + } else { + $orgtypes = array(); + foreach (DB::fetch_all("select orgid,`type` from %t where orgid in(%n)", array($this->_table, $orgid)) as $v) { + if ($v['type'] == 0) { + $orgtypes['org'][] = $v['orgid']; + } else { + $orgtypes['group'][] = $v['orgid']; + } + + } + return $orgtypes; + } + + } + + public function get_uniqueName_by_forgid($forgid, $orgname = '', $orgid = 0) + { + static $i = 0; + if (empty($orgname)) $orgname = lang('new_department'); + + if (DB::result_first("select COUNT(*) from %t where orgname=%s and forgid=%d and orgid!=%d", array($this->_table, $orgname, $forgid, $orgid))) { + $orgname = preg_replace("/\(\d+\)/i", '', $orgname) . '(' . ($i + 1) . ')'; + $i += 1; + return self::get_uniqueName_by_forgid($forgid, $orgname); + } else { + return $orgname; + } + } + + /*空间相关*/ + + /* 获取当前部门机构空间含有的空间限制值(从上向下) + * 包含未分配空间的机构或部门已使用空间(单位为B) + * $owner参数,默认为true即包含自身空间限制占用,设为false,不包含自身空间限制占用 + * */ + public function get_orgallotspace_by_orgid($orgid, $allotspace = 0, $owner = true) + { + $org = self::fetch($orgid); + + //如果当前部门有空间限制值,则返回该值 + if ($org['maxspacesize'] > 0 && $owner) { + + $allotspace += $org['maxspacesize'] * 1024 * 1024; + + } else {//如果当前部门没有分配空间,寻找下级分配空间之和 + + //当前机构或部门已使用空间大小 + $allotspace += intval($org['usesize']); + //下级部门分配空间大小 + foreach (DB::fetch_all("select orgid from %t where forgid = %d", array($this->_table, $orgid)) as $val) { + $allotspace += self::get_orgallotspace_by_orgid($val['orgid']); + } + } + return $allotspace; + } + + + /* * + * 获取系统可分配空间大小 + * 如果系统无空间限制,返回0 + * 如果系统空间设置为-1,返回-1 + * 如果系统空间有设置,且空间使用量超出或等于分配和,返回-2,否则返回剩余可分配值(单位为B) + * */ + public function get_system_allowallot_space() + { + global $_G; + + //获取系统空间设置值 + $systemspace = isset($_G['setting']['systemSpace']) ? intval($_G['setting']['systemSpace']) : 0; + + //系统空间无限制时 + if ($systemspace == 0) { + + $allowallotspace = 0; + + } elseif ($systemspace < 0) {//系统空间关闭时 + + $allowallotspace = -1; + + } elseif ($systemspace > 0) {//设置系统空间限制时 + + //获取所有顶级机构和群组空间限制值 + $fpathkey = DB::fetch_all("select maxspacesize,orgid from %t where forgid = 0", array($this->_table)); + + $allotspace = 0; + foreach ($fpathkey as $v) { + + //如果顶级机构有限制值,计算入限制值当中 + if ($v['maxspacesize'] > 0) { + + $allotspace += intval($v['maxspacesize']) * 1024 * 1024; + } else {//如果当前顶级机构没有限制值,获取当前机构已使用空间值+下层机构限制值之和(包含下层机构无限制的已使用空间) + $allotspace += self::get_orgallotspace_by_orgid($v['orgid']); + } + } + //用户分配空间值 + $allotspace += C::t('user')->get_allotspace(); + $allowallotspace = $systemspace * 1024 * 1024 - $allotspace; + + + if ($allowallotspace <= 0) { + $allowallotspace = -2; + } + } + return $allowallotspace; + + } + + /* + * 获取当前部门空间限制值 + *从下到上依次查找,如果未找到空间限制,则获取系统空间限制,返回值单位为B + * */ + public function get_parent_maxspacesize_by_pathkey($pathkey, $currentorgid) + { + $arr = array('orgid' => '', 'maxspacesize' => ''); + $pathkeys = explode('-', $pathkey); + $pathkeys = array_reverse($pathkeys); + foreach ($pathkeys as $v) { + $orgid = intval(str_replace('_', '', $v)); + + //排除当前部门 + if ($orgid == $currentorgid) { + + continue; + + } else { + + /*//判断是否有该层的管理权限 + if(!C::t('organization_admin')->chk_memberperm($orgid)){ + exit(json_encode(array('error'=>'没有权限'))); + }*/ + //获取当前层分配空间大小 + $result = DB::result_first("select maxspacesize from %t where orgid = %d", array($this->_table, $orgid)); + + if ($result > 0 || $result == -1) { + + $arr['maxspacesize'] = $result * 1024 * 1024; + $arr['orgid'] = $orgid; + break; + } + } + + } + //如果没有获取到上层限制,获取系统空间限制 + if ($arr['maxspacesize'] == '') { + $arr['maxspacesize'] = self::get_system_allowallot_space(); + } + return $arr; + } + + + /* + * 获取当前机构或部门已分配空间大小 + * 包含已使用空间大小 + * 单位为B + * */ + /* public function get_current_occupysize_byorgid($orgid, $return = array()) + { + $org = self::fetch($orgid); + if($org['maxspacesize'] > 0){ + return + } + $return['usesize'] += $org['usesize']; + //获取当前机构子级空间信息 + foreach (DB::fetch_all("select maxspacesize,usesize,orgid from %t where forgid = %d ", array('organization', $orgid)) as $v) { + if ($v['maxspacesize'] > 0) { + $return['maxsize'] += $v['maxspacesize'] * 1024 * 1024; + } elseif ($v['maxspacesize'] == 0) { + $return['maxsize'] += $v['usesize']; + $return = $this->get_current_occupysize_byorgid($v['orgid']); + } + } + return $return; + }*/ + + /* * + * 获取当前机构可分配空间大小 + * 上级限制-上级已占用+当前原值 + * */ + public function get_allowallotspacesize_by_orgid($orgid) + { + $currentallowsetsize = 0; + $org = C::t('organization')->fetch($orgid); + if (!$org) return; + //获取父级可分配空间大小 + $topmaxspacesizeinfo = $this->get_parent_maxspacesize_by_pathkey($org['pathkey'], $orgid); + + //如果当前部门之前有分配空间设置 + if ($org['maxspacesize'] > 0) { + + $oldmaxspacesize = $org['maxspacesize'] * 1024 * 1024; + + } else {//如果当前部门之前无分配空间设置,获取其下级部门分配空间设置与当前部门未分配已使用之和 + + $oldmaxspacesize = $this->get_orgallotspace_by_orgid($orgid); + } + if ($topmaxspacesizeinfo['maxspacesize'] > 0) { + + if ($topmaxspacesizeinfo['orgid']) {//有上级限制 + + //含限制上级空间占用 + $topallotapce = $this->get_orgallotspace_by_orgid($topmaxspacesizeinfo['orgid'], 0, false); + + //计算当前部门可设置空间大小:有限制上级限制空间-有限制上级已占用空间+当前部门原空间 + $currentallowsetsize = $topmaxspacesizeinfo['maxspacesize'] - $topallotapce + $oldmaxspacesize; + + } else {//无上级限制(即使用系统空间限制) + + $currentallowsetsize = $topmaxspacesizeinfo['maxspacesize'] + $oldmaxspacesize; + } + + } else {//返回值为0,-1,-2的特殊情形 + + $currentallowsetsize = $topmaxspacesizeinfo['maxspacesize']; + } + return $currentallowsetsize; + } + + //获取可使用空间大小 + public function get_usespace_size_by_orgid($orgid) + { + $allowusespace = 0; + if (!$org = C::t('organization')->fetch($orgid)) { + return -1; + } + //如果当前机构或部门已设置分配空间 + if ($org['maxspacesize'] > 0) { + + //获取当前机构或部门已占用空间大小 + $currentallotspace = $this->get_orgallotspace_by_orgid($orgid, 0, false); + + //获取当前机构或部门可使用空间大小 + $allowusespace = $org['maxspacesize'] * 1024 * 1024 - $currentallotspace; + + //如果当前机构或部门可使用空间大小不足 + if ($allowusespace <= 0) { + + $allowusespace = -2; + + } + + } elseif ($org['maxspacesize'] < 0) {//如果当前机构或部门已分配空间为-1 + + $allowusespace = -1; + + } elseif ($org['maxspacesize'] == 0) {//如果当前机构或部门未分配空间 + + //获取当前机构或部门可分配空间大小即其可用空间 + $allowusespace = self::get_allowallotspacesize_by_orgid($orgid); + + } + return $allowusespace; + } + + + //获取我有管理权限的机构和部门(包括下级部门)orgids + public function fetch_all_manage_orgids_by_uid($uids,$sub=true){ + if(!is_array($uids)) $uids=(array)$uids; + if(!$orgids=C::t('organization_admin')->fetch_orgids_by_uid($uids)) return array(); + $sql="1"; + $param=array($this->_table); + $sqlarr=array(); + if($sub){ + foreach(parent::fetch_all($orgids) as $value){ + $sqlarr[]='pathkey regexp %s'; + $param[]='^'.$value['pathkey'].'.*'; + } + if($sqlarr){ + $sql.=' and (' . implode(' OR ',$sqlarr).')'; + foreach(DB::fetch_all("select orgid from %t where $sql",$param) as $value){ + $orgids[]=$value['orgid']; + } + } + } + return array_unique($orgids); + } +} diff --git a/core/class/table/table_organization_admin.php b/core/class/table/table_organization_admin.php new file mode 100644 index 0000000..a94ca9a --- /dev/null +++ b/core/class/table/table_organization_admin.php @@ -0,0 +1,208 @@ +_table = 'organization_admin'; + $this->_pk = 'id'; + + parent::__construct(); + } + public function insert($uid, $orgid,$admintype = 1) { + if(!$uid || !$orgid) return 0; + if(!C::t('organization_user')->fetch_num_by_orgid_uid($orgid,$uid)){ + $ret = C::t('organization_user')->insert_by_orgid($orgid,$uid); + } + $id=parent::insert(array("orgid"=>$orgid,'uid'=>$uid,'opuid'=>getglobal('uid'),'dateline'=>TIMESTAMP,'admintype'=>$admintype),1,1); + self::update_groupid_by_uid($uid); + + + return DB::result_first('select id from %t where uid=%d and orgid=%d',array($this->_table,$uid,$orgid)); + } + public function update_perm($uid,$orgid,$admintype){ + if(DB::result_first("select count(*) from %t where orgid = %d and uid = %d",array($this->_table,$orgid,$uid))){ + if($admintype == 0){ + return DB::delete($this->_table,array('orgid'=>$orgid,'uid'=>$uid)); + }else{ + return DB::update($this->_table,array('admintype'=>$admintype),array('orgid'=>$orgid,'uid'=>$uid)); + } + }else{ + return self::insert($uid,$orgid,$admintype); + } + + } + public function delete_by_id($id){ + $data=self::fetch($id); + if($data['admintye'] == 2) return false; + if($return=parent::delete($id)){ + self::update_groupid_by_uid($data['uid']); + } + return $return; + } + //判断是否具有当前部门或机构管理员权限 + public function is_admin_by_orgid($orgid,$uid){ + $currentpathkey = DB::result_first("select pathkey from %t where orgid = %d",array('organization',$orgid)); + $orgids = explode('-',str_replace('_','',$currentpathkey)); + if(DB::result_first("select count(*) from %t where orgid in (%n) and uid = %d",array($this->_table,$orgids,$uid)) > 0){ + return true; + } + return false; + } + /*//判断用户是否是当前机构或部门管理员,或者是下级部门成员 + public function is_curentadmin_or_childmember($orgid,$uid){ + if($this->chk_memberperm($orgid,$uid)) return true; + $currentpathkey = DB::result_first("select pathkey from %t where orgid = %d",array('organization',$orgid)); + $like = $currentpathkey.'.+'; + foreach (DB::fetch_all("select orgid from %t where pathkey REGEXP %s", array('organization', $like)) as $value) { + $gids[] = $value['orgid']; + } + if(count($gids) > 0){ + return DB::result_first("select count(*) from %t where orgid in(%n)",array('organization_user',$gids)); + } + }*/ + public function fetch_group_creater($orgid){ + if(!$orgid) return false; + $uid = DB::result_first("select uid from %t where orgid = %d and admintype = %d",array($this->_table,$orgid,2)); + $username = DB::result_first("select username from %t where uid = %d ",array('user',$uid)); + return $username; + } + public function update_groupid_by_uid($uid){ + return true; + $user=getuserbyuid($uid); + if($user['groupid']==1) return ; + //判断当前用户是否仍为机构和部门管理员 + if(DB::result_first("select COUNT(*) from %t a left join %t o on o.orgid = a.orgid where a.uid=%d and o.type = 0 ",array($this->_table,'organization',$uid))){ + $groupid=2; + }else{ + $groupid=9; + } + return C::t('user')->update($uid,array('groupid'=>$groupid)); + } + public function delete_by_uid($uid) { + if($return=DB::delete($this->_table, "uid='{$uid}'")){ + self::update_groupid_by_uid($uid); + return $return; + }else return false; + } + public function delete_by_orgid($orgids) { + $orgids=(array)$orgids; + $uids=array(); + foreach(DB::fetch_all("select uid from %t where orgid IN (%n) ",array($this->_table,$orgids)) as $value){ + $uids[$value['uid']]=$value['uid']; + } + if($return=DB::delete($this->_table, "orgid IN (".dimplode($orgids).")")){ + foreach($uids as $uid){ + self::update_groupid_by_uid($uid); + } + return $return; + } + return false; + } + public function delete_by_uid_orgid($uid,$orgid) { + + if($return=DB::delete($this->_table, "uid='{$uid}' and orgid='{$orgid}'")){ + self::update_groupid_by_uid($uid); + return $return; + }else return false; + } + + public function fetch_uids_by_orgid($orgids){ + $uids=array(); + if(!is_array($orgids)) $orgids=array($orgids); + $query=DB::query("select uid from %t where orgid IN(%n)",array($this->_table,$orgids)); + while($value=DB::fetch($query)){ + $uids[]=$value['uid']; + } + return $uids; + } + + public function fetch_moderators_by_orgid($orgids,$count=false){ + if(!is_array($orgids)) $orgids=array($orgids); + if($count) return DB::result_first("select COUNT(*) from %t where orgid IN (%n)",array($this->_table,$orgids)); + return DB::fetch_all("select o.* ,u.username,u.email,u.uid from ".DB::table($this->_table). " o LEFT JOIN ".DB::table('user')." u ON o.uid=u.uid where o.orgid IN(".dimplode($orgids).") order by o.dateline DESC"); + } + public function fetch_orgids_by_uid($uids,$orgtype = 0){ + $uids=(array)$uids; + $orgids=array(); + + $param=array($this->_table); + if($orgtype>-1){ + $sql = "select u.orgid from %t u LEFT JOIN %t o ON u.orgid=o.orgid where u.uid IN(%n) and o.type=%d"; + $param[]='organization'; + $param[]=$uids; + $param[]=$orgtype; + }else{ + $sql = "select orgid from %t where uid IN(%n)"; + $param[]=$uids; + } + foreach(DB::fetch_all($sql,$param) as $value){ + $orgids[$value['orgid']]=$value['orgid']; + } + return $orgids; + } + + public function ismoderator_by_uid_orgid($orgid,$uid,$up=1){ + global $_G; + include_once libfile('function/organization'); + if($_G['adminid']==1) return true; + if($up) $orgids=C::t('organization')->fetch_parent_by_orgid($orgid); + else $orgids=array($orgid); + return DB::result_first("select COUNT(*) from %t where orgid IN (%n) and uid=%d ",array($this->_table,$orgids,$uid)); + } + + public function fetch_toporgids_by_uid($uid){ + $ret=array(); + $orgids=self::fetch_orgids_by_uid($uid); + foreach(C::t('organization')->fetch_all($orgids) as $value){ + $topids=explode('-',$value['pathkey']); + $topid=intval(str_replace('_','',$topids[0])); + $ret[$topid]=$topid; + } + return $ret; + } + public function chk_memberperm($orgid,$uid = 0){ + global $_G; + $perm = 0; + if(!$org=C::t('organization')->fetch($orgid)) return $perm; + if(!$uid) $uid = $_G['uid']; + if($_G['adminid'] == 1 && $uid == $_G['uid']) { + $perm = 2; + return $perm; + } + + //判断是否有上级,如果有上级并且当前用户为上级管理员,则给予类似创始人权限 + if($org['forgid']){ + $orgids = C::t('organization')->fetch_parent_by_orgid($orgid); + $key = array_search($orgid,$orgids); + unset($orgids[$key]); + if(DB::result_first("select count(*) from %t where orgid in(%n) and uid = %d",array($this->_table,$orgids,$uid)) > 0){ + $perm = 2; + return $perm; + } + } + if($admintype = DB::result_first("select admintype from %t where orgid = %d and uid = %d",array($this->_table,$orgid,$uid))){ + $perm = $admintype; + } + return $perm; + } + + public function fetch_adminer_by_orgid($orgid){ + $admindata = ''; + foreach(DB::fetch_all("select u.username from %t a left join %t u on a.uid = u.uid where orgid = %d ",array($this->_table,'user',$orgid)) as $v){ + $admindata .= $v['username'].','; + } + $admindata = substr($admindata,0,-1); + return $admindata; + } +} diff --git a/core/class/table/table_organization_job.php b/core/class/table/table_organization_job.php new file mode 100644 index 0000000..06a6266 --- /dev/null +++ b/core/class/table/table_organization_job.php @@ -0,0 +1,54 @@ +_table = 'organization_job'; + $this->_pk = 'jobid'; + parent::__construct(); + } + public function fetch_all_by_orgid($orgid,$up=0){ + $data=array(); + foreach(DB::fetch_all("select * from %t where orgid = %d order by orgid",array($this->_table,$orgid)) as $value){ + $data[$value['jobid']]=$value; + } + return $data; + } + function fetch_by_jobid($jobid){ + include_once libfile('function/organization'); + $data=parent::fetch($jobid); + $data['orgtree']=getTreeByOrgid($data['orgid']); + return $data; + } + + function insert_job_by_name($orgid=0, $name="" ){ + if (!$orgid || !$name ) return 0; + if( !$jobid = DB::result_first("select jobid from %t where orgid = %d and name=%s", array('organization_job',$orgid,$name)) ) { + $data=array( + "orgid" => $orgid, + 'name' => $name, + 'jobid' => 0, + 'dateline' => TIMESTAMP + ); + if($jobid = DB::insert('organization_job',$data,1)){//插入版本数据 + return $jobid; + } + }else{ + return $jobid; + } + return 0; + } +} + +?> diff --git a/core/class/table/table_organization_upjob.php b/core/class/table/table_organization_upjob.php new file mode 100644 index 0000000..108120d --- /dev/null +++ b/core/class/table/table_organization_upjob.php @@ -0,0 +1,45 @@ +_table = 'organization_upjob'; + $this->_pk = 'id'; + parent::__construct(); + } + public function fetch_by_uid($uid){ + if(!$data=DB::fetch_first("select * from %t where uid=%d ",array($this->_table,$uid))) return array(); + if(!$job=C::t('organization_job')->fetch_by_jobid($data['jobid'])) return array(); + $job['depart']=array(); + foreach($job['orgtree'] as $value){ + $job['depart'][]=$value['orgname']; + } + $job['depart']=implode(' - ',$job['depart']); + return array_merge($data,$job); + } + public function insert_by_uid($uid,$jobid){ + if(!$jobid ) return self::delete_by_uid($uid); + $setarr=array('uid'=>$uid, + 'jobid'=>$jobid, + 'dateline'=>TIMESTAMP, + 'opuid'=>getglobal('uid') + ); + return parent::insert($setarr,1,1); + } + public function delete_by_uid($uid){ + return DB::query("delete from %t where uid=%d",array($this->_table,$uid)); + } +} + +?> diff --git a/core/class/table/table_organization_user.php b/core/class/table/table_organization_user.php new file mode 100644 index 0000000..bee876b --- /dev/null +++ b/core/class/table/table_organization_user.php @@ -0,0 +1,428 @@ +_table = 'organization_user'; + $this->_pk = ''; + parent::__construct(); + } + + public function insert_by_orgid($orgid,$uids,$jobid = 0) + { + if (!$uids || !$orgid) return array(); + if(!$org = C::t('organization')->fetch($orgid)) { + return array(); + } + if (!is_array($uids)) $uids=array($uids); + $ret=array(); + foreach ($uids as $v) { + if(parent::insert(array("orgid" => $orgid, 'uid' => $v, 'jobid' => $jobid, 'dateline' => TIMESTAMP), 1, 1)){ + $ret[$v]=$v; + } + } + if( $org["type"]==0){//非群组才同步 + self::syn_user( $ret ); + } + return $ret; + } + + public function fetch_by_uid_orgid($uid, $orgid) + { + return DB::fetch_first("select * from %t where uid=%d and orgid=%d", array($this->_table, $uid, $orgid)); + } + + public function replace_orgid_by_uid($uid, $orgarr) + { + $orgids = array(); + foreach ($orgarr as $key => $value) { + $orgids[] = $key; + } + + $Oorgids = self::fetch_orgids_by_uid($uid); + if (!is_array($orgids)) $orgids = array($orgids); + $insertids = array_diff($orgids, $Oorgids); + $delids = array_diff($Oorgids, $orgids); + $updateids = array_diff($orgids, $delids, $insertids); + if ($delids) DB::delete($this->_table, "uid='{$uid}' and orgid IN (" . dimplode($delids) . ")"); + foreach ($insertids as $orgid) { + if ($orgid > 0) self::insert_by_orgid($orgid,$uid,$orgarr[$orgid]); + } + foreach ($updateids as $orgid) { + if ($orgid > 0) DB::update($this->_table, array('jobid' => $orgarr[$orgid]), "orgid='{$orgid}' and uid='{$uid}'"); + } + return true; + } + + public function bind_uid_and_orgid($uid, $orgarr){ + $orgids = array(); + foreach ($orgarr as $key => $value) { + $orgids[] = $key; + } + + $Oorgids = self::fetch_orgids_by_uid($uid); + if (!is_array($orgids)) $orgids = array($orgids); + $insertids = array_diff($orgids, $Oorgids); + $delids = array_diff($Oorgids, $orgids); + $updateids = array_diff($orgids, $delids, $insertids); + //if ($delids) DB::delete($this->_table, "uid='{$uid}' and orgid IN (" . dimplode($delids) . ")"); + + foreach ($insertids as $orgid) { + if ($orgid > 0) self::insert_by_orgid($orgid,$uid,$orgarr[$orgid]); + } + foreach ($updateids as $orgid) { + if ($orgid > 0) DB::update($this->_table, array('jobid' => $orgarr[$orgid]), "orgid='{$orgid}' and uid='{$uid}'"); + } + + return true; + } + + public function delete_by_uid($uid, $wxupdate = 1) + { + if ($return = DB::delete($this->_table, "uid='{$uid}'")) { + + self::syn_user( $uid ); + return $return; + } else return false; + } + + public function delete_by_uid_orgid($uids, $orgid, $wxupdate = 1) + { + $uids = (array)$uids; + $uidarr = array(); + //获取管理员用户 + foreach (DB::fetch_all("select uid,admintype from %t where uid in(%n) and orgid = %d ", array('organization_admin', $uids, $orgid)) as $v) { + $uidarr[] = array('uid' => $v['uid'], 'perm' => $v['admintype']); + $key = array_search($v['uid'], $uids); + unset($uids[$key]); + } + //如果有管理员用户,忽略无权限删除的用户 + if (count($uidarr) > 0) { + //获取当前操作用户权限 + $perm = C::t('organization_admin')->chk_memberperm($orgid, getglobal('uid')); + foreach ($uidarr as $val) { + if ($perm > $val['perm']) { + $uids[] = $val['uid']; + } + } + } + if ($return = DB::delete($this->_table, "uid IN (" . dimplode($uids) . ") and orgid='{$orgid}'")) { + //删除管理员表数据 + DB::delete('organization_admin', "uid IN (" . dimplode($uids) . ") and orgid='{$orgid}'"); + include_once libfile('function/cache'); + updatecache('organization'); + self::syn_user( $uids ); + return $uids; + } else return false; + } + + public function delete_by_orgid($orgids) + { + if (!$orgids) return; + $orgids = (array)$orgids; + //$uids = self::fetch_uids_by_orgid($orgids); + $syn_uid =array(); + foreach ($orgids as $orgid) { + $org = DB::fetch_first("select orgid,type from %t where orgid=%d", array('organization', $orgid)); + if( $org ){ + $query = DB::query("select uid from %t where orgid=%d", array($this->_table, $orgid)); + while ($value = DB::fetch($query)) { + if( $org["type"]==0 ) $syn_uid[]=$value['uid']; + } + } + } + + if( $syn_uid ) $syn_uid = array_unique($syn_uid); + + if ($return = DB::delete($this->_table, "orgid IN (" . dimplode($orgids) . ")")) { + if ($syn_uid) self::syn_user( $syn_uid ); + return $return; + } else return false; + } + + public function fetch_org_by_uid($uids,$orgtype=0) + { + $uids=(array)$uids; + $orgids=array(); + + $param=array($this->_table); + if($orgtype>-1){ + $sql = "select u.orgid from %t u LEFT JOIN %t o ON u.orgid=o.orgid where u.uid IN(%n) and o.type=%d"; + $param[]='organization'; + $param[]=$uids; + $param[]=$orgtype; + }else{ + $sql = "select orgid from %t where uid IN(%n)"; + $param[]=$uids; + } + foreach(DB::fetch_all($sql,$param) as $value){ + $orgids[$value['orgid']]=$value['orgid']; + } + return $orgids; + } + + public function fetch_uids_by_orgid($orgids) + { + $uids = array(); + if (!is_array($orgids)) $orgids = array($orgids); + $query = DB::query("select uid from %t where orgid IN(%n)", array($this->_table, $orgids)); + while ($value = DB::fetch($query)) { + $uids[] = $value['uid']; + } + unset($query); + return $uids; + } + + public function fetch_user_not_in_orgid($limit = 10000) + { + $limitsql=''; + if($limit) $limitsql="limit $limit"; + //获取属于机构和部门的用户 + $uids_org=array(); + foreach(DB::fetch_all("SELECT u.uid from %t u LEFT JOIN %t o ON u.orgid=o.orgid where o.type='0'",array($this->_table,'organization')) as $value){ + $uids_org[$value['uid']]=$value['uid']; + } + //获取不属于所有机构和部门的用户 + return DB::fetch_all("select username,uid,email,groupid from %t where uid NOT IN(%n) order by username $limitsql ",array('user',$uids_org),'uid'); + } + + public function fetch_user_by_orgid($orgids, $limit = 0, $count = false) + { + if (!is_array($orgids)) $orgids = array($orgids); + $limitsql = ''; + if ($limit) $limitsql = "limit $limit"; + + if ($count) return DB::result_first("select COUNT(*) %t where orgid IN(%n)", array($this->_table, $orgids)); + return DB::fetch_all("select o.* ,u.username,u.email,u.groupid from " . DB::table('organization_user') . " o LEFT JOIN " . DB::table('user') . " u ON o.uid=u.uid where o.orgid IN(" . dimplode($orgids) . ") order by dateline DESC $limitsql "); + } + + public function fetch_orgids_by_uid($uids,$orgtype = 0){ + $uids=(array)$uids; + $orgids=array(); + + $param=array($this->_table); + if($orgtype>-1){ + $sql = "select u.orgid from %t u LEFT JOIN %t o ON u.orgid=o.orgid where u.uid IN(%n) and o.type=%d"; + $param[]='organization'; + $param[]=$uids; + $param[]=$orgtype; + }else{ + $sql = "select orgid from %t where uid IN(%n)"; + $param[]=$uids; + } + foreach(DB::fetch_all($sql,$param) as $value){ + $orgids[$value['orgid']]=$value['orgid']; + } + return $orgids; + } + + //判断用户是否为当前部门成员 + public function fetch_num_by_orgid_uid($orgid, $uid) + { + if (!$orgid || !$uid) return false; + if (DB::result_first("select count(*) from %t where uid = %d and orgid = %d", array($this->_table, $uid, $orgid))) { + return true; + } else { + return false; + } + + } + + public function fetch_usernums_by_orgid($orgid) + { + if (!$orgid) return ''; + $numbers = DB::result_first("select count(*) from %t where orgid = %d", array($this->_table, $orgid)); + return $numbers; + } + + public function fetch_usernum_by_orgid($orgid) + { + if (!$orgid) return false; + $orgid = intval($orgid); + if ($result = DB::result_first("select count(*) from %t where orgid = %d", array($this->_table, $orgid))) { + return $result; + } + return false; + } + + public function fetch_all_by_uid($uids) + { + $uids = (array)$uids; + return DB::fetch_all("select * from %t where uid IN(%n) ", array($this->_table, $uids)); + } + + + public function move_to_forgid_by_orgid($forgid, $orgid) + {//移动用户到上级部门 + if (!$org = C::t('organization')->fetch($forgid)) return false; + if (!$org['forgid']) { + foreach (DB::fetch_all("select * from %t where orgid=%d", array($this->_table, $orgid)) as $value) { + C::t('organization_admin')->delete_by_uid_orgid($value['uid'], $orgid); + } + + return self::delete_by_orgid($orgid); + } + foreach (DB::fetch_all("select * from %t where orgid=%d", array($this->_table, $orgid)) as $value) { + if (DB::result_first("select COUNT(*) from %t where orgid=%d and uid=%d", array($this->_table, $org['forgid'], $value['uid']))) { + C::t('organization_admin')->delete_by_uid_orgid($value['uid'], $orgid); + DB::delete($this->_table, "orgid='{$org[forgid]}' and uid='{$value[uid]}'"); + } else { + $value['orgid'] = $org['forgid']; + parent::insert($value); + } + } + + return true; + } + + public function move_to_by_uid_orgid($uid, $orgid, $torgid, $copy) + { + if ($orgid == $torgid) return true; + if ($torgid == 0) { + C::t('organization_admin')->delete_by_uid_orgid($uid, $orgid); + return self::delete_by_uid_orgid($uid, $orgid); + } + if (!$copy && DB::result_first("select COUNT(*) from %t where orgid=%d and uid=%d", array($this->_table, $torgid, $uid))) { + C::t('organization_admin')->delete_by_uid_orgid($uid, $orgid); + return self::delete_by_uid_orgid($uid, $orgid, 0); + } else { + self::insert_by_orgid($torgid,$uid); + if (!$copy) self::delete_by_uid_orgid($uid, $orgid, 0); + return true; + } + } + //查询成员 + public function fetch_user_byorgid($orgid, $username = '') + { + $where = " and 1=1"; + $params = array($this->_table, 'user', $orgid); + if ($username) { + $uid = DB::result_first("select uid from %t where username like %s", array('user', '%' . $username . '%')); + $where .= " and o.uid = %d"; + $params[] = $uid; + } + $userinfo = array(); + foreach (DB::fetch_all("select o.*,u.username,u.email from %t o left join %t u on o.uid = u.uid where o.orgid = %d $where", $params) as $v) { + $admintype = DB::result_first("select admintype from %t where orgid = %d and uid = %d", array('organization_admin', $orgid, $v['uid'])); + if (!$admintype) { + $v['perm'] = 0; + } else { + $v['perm'] = $admintype; + } + $userinfo[] = $v; + } + return $userinfo; + } + //获取当前机构或部门及下级所有的用户 + public function get_all_user_byorgid($orgid){ + $pathkey = DB::result_first("select pathkey from %t where orgid = %d",array('organization',$orgid)); + $params = array('organization','organization_user','user','^'.$pathkey.'.*'); + $userinfo = array(); + foreach (DB::fetch_all("select o.orgid,ou.*,u.username,u.email from %t o + left join %t ou on ou.orgid = o.orgid + left join %t u on ou.uid = u.uid where o.pathkey regexp %s", $params) as $v) { + $admintype = DB::result_first("select admintype from %t where orgid = %d and uid = %d", array('organization_admin', $orgid, $v['uid'])); + if (!$admintype) { + $v['perm'] = 0; + } else { + $v['perm'] = $admintype; + } + $userinfo[] = $v; + } + return $userinfo; + } + + //设置成员权限 + public function set_admin_by_giduid($uid, $gid, $perm = 0)//perm,0为协作成员,1为管理员,2为创始人 + { + global $_G; + $uid = intval($uid); + $gid = intval($gid); + if (!$group = C::t('organization')->fetch($gid)) array('error' => lang('group_not_exists')); + + //获取操作用户权限 + $doperm = C::t('organization_admin')->chk_memberperm($gid, $_G['uid']); + if ($perm == 2 && $doperm != 2) return array('error' => lang('no_privilege'));//检查权限 + + $permtitle = lang('explorer_gropuperm'); + //查詢用戶是否存在 + if ($result = DB::fetch_first("select ou.*,u.username from %t ou + left join %t u on ou.uid=u.uid where ou.orgid=%d and ou.uid = %d", array($this->_table, 'user', $gid, $uid))) { + //转让创始人 + if ($perm == 2) { + $olduser = DB::fetch_first("select u.uid,u.username from %t ou + left join %t u on ou.uid = u.uid where ou.orgid = %d and ou.admintype = %d", array('organization_admin', 'user', $gid, 2)); + if (C::t('organization_admin')->update_perm($uid, $gid, $perm) && DB::delete('organization_admin', array('orgid' => $gid, 'uid' => $olduser['uid']))) { + return array('success' => lang('change_creater_succeed'), 'perm' => $perm, 'olduid' => $olduser['uid'],'olduser'=>$olduser,'member'=>$result['username']); + } + } elseif (C::t('organization_admin')->update_perm($uid, $gid, $perm)) {//设置管理员 + return array('success' => true, 'perm' => $perm,'member'=>$result['username']); + } + } + return array('error' => lang('explorer_do_failed')); + } + + //查询机构下成员数 + public function fetch_num_by_toporgid($orgid) + { + $pathkey = DB::result_first("select pathkey from %t where orgid = %d", array('organization', $orgid)); + $orgidarr = array(); + foreach (DB::fetch_all("select orgid from %t where pathkey regexp %s", array('organization', '^' . $pathkey . '.*')) as $v) { + $orgidarr[] = $v['orgid']; + } + $uidarr = array(); + foreach (DB::fetch_all("select uid from %t where orgid in (%n)", array($this->_table, $orgidarr)) as $v) { + $uidarr[] = $v['uid']; + } + $uidarr = array_unique($uidarr); + return count($uidarr); + } + + public function fetch_parentadminer_andchild_uid_by_orgid($orgid,$partget=true) + { + $uid = getglobal('uid'); + $uids = array('adminer'=>array(),'partmember'=>array()); + $orgid = intval($orgid); + $parentadminer = array(); + //获取具有管理员权限的用户 + $pathkey = DB::result_first("select pathkey from %t where orgid = %d", array('organization', $orgid)); + $gids = explode('-',str_replace('_','',$pathkey)); + foreach(DB::fetch_all("select uid from %t where orgid in(%n)",array('organization_admin',$gids)) as $v){ + $uids['adminer'][] = $v['uid']; + } + if($partget){ + //获取没有管理员权限的用户 + $childgids = array($orgid); + $like = $pathkey.'.+'; + foreach (DB::fetch_all("select orgid from %t where pathkey REGEXP %s", array('organization', $like)) as $value) { + $childgids[] = $value['orgid']; + } + $childuids = array(); + foreach(DB::fetch_all("select uid from %t where orgid in(%n)",array($this->_table,$childgids)) as $v){ + $childuids[] = $v['uid']; + } + $uids['partmember'] = array_diff(array_unique($childuids),$uids['adminer']); + } + $uids['all'] = array_merge($uids['partmember'],$uids['adminer']); + return $uids; + } + + public function syn_user( $data=array() ){ + Hook::listen('syntoline_user',$data);//注册绑定到钉钉用户表 + //Hook::listen('dzztowxwork_synuser',$data);//注册绑定到企业微信用户表 + } + +} + diff --git a/core/class/table/table_process.php b/core/class/table/table_process.php new file mode 100644 index 0000000..bdec969 --- /dev/null +++ b/core/class/table/table_process.php @@ -0,0 +1,30 @@ +_table = 'process'; + $this->_pk = 'processid'; + + parent::__construct(); + } + + public function delete_process($name, $time) { + $name = addslashes($name); + return DB::delete('process', "processid='$name' OR expiry<".intval($time)); + } +} + +?> diff --git a/core/class/table/table_resources.php b/core/class/table/table_resources.php new file mode 100644 index 0000000..ab49189 --- /dev/null +++ b/core/class/table/table_resources.php @@ -0,0 +1,1058 @@ +_table = 'resources'; + $this->_pk = 'rid'; + $this->_pre_cache_key = 'resources_'; + $this->_cache_ttl = 60 * 60; + + parent::__construct(); + } + + public function insert_data($data, $rid = '') + { + $data['rid'] = ($rid) ? $rid : self::create_id(); + if (parent::insert($data)) { + return $data['rid']; + } + return false; + } + + //生成主键rid + public function create_id() + { + $microtime = microtime(); + list($msec, $sec) = explode(' ', $microtime); + $msec = $msec * 1000000; + $idstr = md5($sec . $msec . random(6)); + return $idstr; + } + + /* public function getparentsuri($pfid) + { + $path = array(); + if ($parent = DB::result_first('select pfid,fname from %t where fid = %d', array('folder', $pfid))) { + if ($parent['pfid'] > 0 && $parent['pfid'] != $pfid) { + $path[] = $parent['fname']; + self::getparenturi($parent['pfid']); + } + } + $path = array_reverse($path); + $path = implode('/', $path); + return $path; + }*/ + public function update_by_pfids($pfids, $setarr) + { + if (!is_array($pfids)) $pfids = (array)$pfids; + $rids = array(); + foreach (DB::fetch_all("select rid from %t where pfid in(%n)", array('resources', $pfids)) as $v) { + $rids[] = $v['rid']; + } + return self::update_by_rid($rids, $setarr); + } + + public function rename_by_rid($rid, $newname) + { + global $_G; + $uid = $_G['uid']; + if (!$infoarr = $this->fetch_info_by_rid($rid)) { + return array('error' => lang('file_not_exist')); + } + $cachkey = 'resourcesdata_' . $rid; + $updatepath = false; + if ($infoarr['type'] == 'folder') { + $updatepath = true; + } + $fid = $infoarr['pfid']; + if (!perm_check::checkperm_Container($infoarr['pfid'], 'edit2') && !($_G['uid'] == $infoarr['uid'] && perm_check::checkperm_Container($infoarr['pfid'], 'edit1'))) { + return array('error' => true); + } + $setarr = array( + 'isdelete' => 1, + 'deldateline' => time() + ); + $position = C::t('resources_path')->fetch_pathby_pfid($fid); + $position = preg_replace('/dzz:(.+?):/', '', $position); + //DB::update($this->_table, array('name' => $newname, 'dateline' => TIMESTAMP), array('rid' => $rid)) + if (self::update_by_rid($rid, array('name' => $newname, 'dateline' => TIMESTAMP))) { + if ($updatepath) { + C::t('folder')->update($infoarr['oid'], array('fname' => $newname)); + C::t('resources_path')->update_path_by_fid($infoarr['oid'], $newname); + } + //更新属性表数据 + C::t('resources_attr')->update_by_skey($rid, $infoarr['vid'], array('title' => $newname)); + //更新缓存 + $cachkey = 'resourcesdata_' . $rid; + $this->clear_cache($cachkey); + $statisdata = array( + 'uid' => getglobal('uid'), + 'edits' => 1, + 'editdateline' => TIMESTAMP + ); + C::t('resources_statis')->add_statis_by_rid($rid, $statisdata); + $hash = C::t('resources_event')->get_showtpl_hash_by_gpfid($infoarr['pfid'], $infoarr['gid']); + $eventdata = array('username' => $_G['username'], 'position' => $position, 'filename' => $infoarr['name'], 'newfilename' => $newname, 'hash' => $hash); + C::t('resources_event')->addevent_by_pfid($infoarr['pfid'], 'rename_file', 'rename', $eventdata, $infoarr['gid'], $rid, $infoarr['name']); + $this->clear_cache($cachkey); + $this->clear_cache($rid); + return array('newname' => $newname); + } + return array('error' => true); + } + + //查询文件表基础信息 $notisdelete是否是已删除 + public function fetch_info_by_rid($rid, $notisdelete = false) + { + if (!$data = parent::fetch($rid)) return false; + if ($notisdelete) { + if ($data['isdelete'] > 0) return false; + } + return $data; + } + + //检查目录权限 如删除,复制,剪切 + public function check_folder_perm($icoarr, $action, $isdelete = false) + { + global $_G; + if ($action == 'cut') $action = 'delete'; + //获取文件夹fid集合 + $fids = C::t('resources_path')->fetch_folder_containfid_by_pfid($icoarr['oid']); + $rids = array(); + $resources = array(); + $extrasql = ''; + if (!$isdelete) { + $extrasql = ' and isdelete < 1 '; + } + //获取当前文件下所有下级rid + foreach (DB::fetch_all("select rid,pfid,oid,uid,sperm from %t where (oid in(%n) or pfid in(%n)) and rid != %s $extrasql", array($this->_table, $fids, $fids, $icoarr['rid'])) as $v) { + $rids[] = $v['rid']; + $resources[] = $v; + } + $index = array_search($icoarr['oid'], $fids); + unset($fids[$index]); + $ridnum = count($rids); + $fidnum = count($fids); + if ($icoarr['gid'] > 0) { + $folderinfo = C::t('folder')->fetch($icoarr['oid']); + if (!perm_FolderSPerm::isPower($folderinfo['fsperm'], $action)) return array('error' => lang('has_no_privilege_file')); + //判断目录是否为空,为空则不判断当前目录权限 + if ($ridnum) { + if (perm_check::checkperm_Container($icoarr['pfid'], $action . '2') || ($_G['uid'] == $folderinfo['uid'] && perm_check::checkperm_Container($icoarr['pfid'], $action . '1'))) { + if (!perm_check::checkperm_Container($icoarr['oid'], $action . '2') && !($_G['uid'] == $folderinfo['uid'] && perm_check::checkperm_Container($icoarr['oid'], $action . '1'))) return array('error' => lang('has_no_privilege_file')); + } else { + return array('error' => lang('has_no_privilege_file')); + } + } else { + //判断是否具有上级删除权限 + if (!perm_check::checkperm_Container($icoarr['pfid'], $action . '2') && !($_G['uid'] == $folderinfo['uid'] && perm_check::checkperm_Container($icoarr['pfid'], $action . '1'))) { + return array('error' => lang('has_no_privilege_file')); + } + } + if (count($resources)) { + foreach ($resources as $v) { + if (!perm_check::checkperm($action, $v)) { + return array('error' => lang('has_no_privilege_file')); + } + } + } + } + return array($icoarr['oid'], $ridnum, $fidnum, $fids, $rids); + } + + //删除文件(移动文件到回收站) + public function recyle_by_rid($rid) + { + global $_G; + $uid = $_G['uid']; + $rid = trim($rid); + $dels = array(); + //判断文件是否存在 + if (!$infoarr = parent::fetch($rid)) { + return false; + } + $parentfid = $infoarr['pfid'];//父级目录 + $setarr = array( + 'pfid' => -1, + 'isdelete' => 1, + 'deldateline' => TIMESTAMP + ); + $setarr1 = array( + 'isdelete' => 1, + 'deldateline' => TIMESTAMP + ); + //如果删除的是文件夹 + if ($infoarr['type'] == 'folder') { + $result = self::check_folder_perm($infoarr, 'delete'); + if ($result['error']) { + return array('error' => $result['error']); + } else { + list($currentfid, $ridnum, $fidnum, $fids, $rids) = $result; + } + if (self::update_by_rid($rid, $setarr)) { + $infoarr['deldateline'] = $setarr['deldateline']; + $infoarr['isdelete'] = $setarr['isdelete']; + //更改下级目录删除状态 + if ($ridnum) self::update_by_rid($rids, $setarr1); + //查询回收站是否有相同数据,如果有合并回收站数据 + if ($recyledata = C::t('resources_recyle')->fetch_by_rid($infoarr['rid'])) { + + if (C::t('folder')->update($currentfid, $setarr)) { + if ($fidnum) DB::update('folder', $setarr1, 'fid in(' . dimplode($rfids) . ')'); + DB::update('resources_recyle', array('deldateline' => $infoarr['deldateline'], 'uid' => $uid), array('id' => $recyledata['id'])); + } else { + if ($ridnum) DB::update($this->table, array('isdelete' => 0, 'deldateline' => 0, 'pfid' => $infoarr['pfid']), 'rid in(' . dimplode($rids) . ')'); + self::update_by_rid($rid, array('isdelete' => 0, 'deldateline' => 0, 'pfid' => $infoarr['pfid'])); + return array('error' => lang('do_failed')); + } + } else { + if (C::t('folder')->update($currentfid, $setarr)) { + if ($fidnum) DB::update('folder', $setarr1, 'fid in(' . dimplode($rfids) . ')'); + C::t('resources_recyle')->insert_data($infoarr); + } else { + if ($ridnum) self::update_by_rid($rids, array('isdelete' => 0, 'deldateline' => 0, 'pfid' => $infoarr['pfid'])); + self::update_by_rid($rid, array('isdelete' => 0, 'deldateline' => 0, 'pfid' => $infoarr['pfid'])); + return array('error' => lang('do_failed')); + } + } + + } + $dels[] = $rid; + } else { + //文件权限判断 + if (!perm_check::checkperm_Container($parentfid, 'delete2') && !($uid == $infoarr['uid'] && perm_check::checkperm_Container($parentfid, 'delete1'))) { + return array('error' => lang('no_privilege')); + } + if (DB::result_first("select count(*) from %t where rid = %s", array('resources_recyle', $rid))) { + return array('error' => lang('file_isdelete_in_recycle')); + } + //执行删除 + if (self::update_by_rid($rid, $setarr)) { + //修改分享表状态 + C::t('shares')->change_by_rid($rid); + $infoarr['deldateline'] = $setarr['deldateline']; + $infoarr['isdelete'] = $setarr['isdelete']; + //数据放入回收站表 + if (C::t('resources_recyle')->insert_data($infoarr)) { + $dels[] = $rid; + } else {//放入回收站失败处理 + self::update_by_rid($rid, array('isdelete' => 0, 'deldateline' => 0, 'pfid' => $infoarr['pfid'])); + } + } + } + + return $dels; + } + + /*返回1,正常删除,需删除附属表数据,返回2,非删除状态内容,只删除回收站表数据,返回3删除失败 + *$force=>是否彻底删除(即是否强制删除非删除状态文件) + * */ + public function deletesourcedata($resource, $force = false) + { + $type = $resource['type']; + $oid = $resource['oid']; + switch ($type) { + case 'folder': + return C::t('folder')->delete_by_fid($oid, $force); + case 'link': + C::t('collect')->delete_by_cid($oid); + return 1; + case 'app': + return 1; + case 'user': + return 1; + case 'pan': + return 1; + case 'storage': + return 1; + default : + if (!$resource['vid']) { + C::t('attachment')->delete_by_aid($resource['aid']); + } + return 1; + } + } + + public function delete_by_rid($rid, $force = false) + { //删除图标 + global $_G; + $cachekey = 'resourcesdata_' . $rid; + $data = self::getsourcedata($rid); + $status = self::deletesourcedata($data, $force); + //删除相关数据 + if ($status == 1) { + //刪除属性表数据 + C::t('resources_attr')->delete_by_rid($rid); + //删除事件表数据 + C::t('resources_event')->delete_by_rid($rid); + //删除标签表数据 + C::t('resources_tag')->delete_by_rid($rid); + //删除回收站数据 + C::t('resources_recyle')->delete_by_rid($rid); + //删除版本表数据 + if ($data['vid']) { + C::t('resources_version')->delete_by_rid($rid); + } + //删除收藏表数据 + C::t('resources_collect')->delete_by_rid($rid); + //删除统计表数据 + C::t('resources_statis')->delete_by_rid($rid); + //删除resources表数据 + if (parent::delete($rid)) { + //处理删除后空间大小 + if (!$data['vid'] && $data['size']) {//更新空间大小 + SpaceSize(-$data['size'], $data['gid'], true, $data['uid']); + } + //记录删除事件 + $hash = C::t('resources_event')->get_showtpl_hash_by_gpfid($data['pfid'], $data['gid']); + $eventdata = array('username' => $_G['username'], 'position' => $data['relpath'], 'filename' => $data['name'], 'hash' => $hash); + C::t('resources_event')->addevent_by_pfid($data['pfid'], 'finallydel_file', 'finallydelete', $eventdata, $data['gid'], $rid, $data['name']); + $this->clear_cache($cachekey); + return true; + } else { + return false; + } + } elseif ($status == 2) { + $this->clear_cache($rid); + $this->clear_cache($cachekey); + //删除回收站数据 + C::t('resources_recyle')->delete_by_rid($rid); + } else { + return false; + } + + } + + public function getsourcedata($rid) + { + //查询索引表数据 + $resourcedata = array(); + if (!$resourcedata = self::fetch($rid)) { + return array(); + } + //查询文件夹信息 + if ($resourcedata['type'] == 'folder') { + $folder = C::t('folder')->fetch_by_fid($resourcedata['oid']); + $resourcedata = array_merge($resourcedata, $folder); + $folderattr = C::t('folder_attr')->fetch_all_folder_setting_by_fid($resourcedata['oid']); + $resourcedata = array_merge($resourcedata, $folderattr); + } + //查询文件路径 + if ($path = C::t('resources_path')->fetch_pathby_pfid($resourcedata['pfid'])) { + $resourcedata['path'] = ($resourcedata['type'] == 'folder') ? $path . $resourcedata['name'] . '/' : $path . $resourcedata['name']; + } + $vdata = array(); + if ($resourcedata['vid'] > 0) { + $vdata = C::t('resources_version')->fetch($resourcedata['vid']); + } + $versiondata = array(); + if ($vdata) { + $versiondata = array( + 'dateline' => $vdata['dateline'],//文件修改时间 + ); + } + //查询文件属性信息 + $attrdata = C::t('resources_attr')->fetch_by_rid($rid, $resourcedata['vid']); + $resourcedata = array_merge($resourcedata, $attrdata); + + $resourcedata = array_merge($resourcedata, $versiondata); + + if ($resourcedata['aid']) {//查询附件数据 + $attachment = C::t('attachment')->fetch($resourcedata['aid']); + //附件表上传时间和文件创建时间字段名称冲突 + $attachment['olddateline'] = $attachment['dateline']; + unset($attachment['dateline']); + $resourcedata = array_merge($resourcedata, $attachment); + } + return $resourcedata; + } + + public function fetch_by_rid($rid, $force_from_db = false) + { //返回一条数据同时加载资源表数据 + global $_G; + $cachekey = 'resourcesdata_' . $rid; + if ($data = $this->fetch_cache($cachekey)) { + return $data; + } + $data = array(); + if (!$data = self::getsourcedata($rid)) { + return array(); + } + $data['size'] = isset($data['size']) ? $data['size'] : 0; + if ($data['type'] == 'image') { + $data['img'] = DZZSCRIPT . '?mod=io&op=thumbnail&size=small&path=' . dzzencode('attach::' . $data['aid']); + $data['url'] = DZZSCRIPT . '?mod=io&op=thumbnail&size=large&path=' . dzzencode('attach::' . $data['aid']); + } elseif ($data['type'] == 'attach' || $data['type'] == 'document') { + $data['img'] = isset($data['img']) ? $data['img'] :geticonfromext($data['ext'], $data['type']); + $data['url'] = DZZSCRIPT . '?mod=io&op=getStream&path=' . dzzencode('attach::' . $data['aid']); + } elseif ($data['type'] == 'shortcut') { + $data['ttype'] = $data['tdata']['type']; + $data['ext'] = $data['tdata']['ext']; + } elseif ($data['type'] == 'dzzdoc') { + $data['url'] = DZZSCRIPT . '?mod=document&icoid=' . dzzencode('attach::' . $data['aid']); + $data['img'] = isset($data['img']) ? $data['img'] : geticonfromext($data['ext'], $data['type']); + } elseif ($data['type'] == 'folder') { + //$contaions = self::get_contains_by_fid($data['oid'], true); + //$data['contaions'] = $contaions; + $relativepath = str_replace(':', '', strrchr($data['path'], ':')); + $data['position'] = substr($relativepath, 0, strlen($relativepath) - 1); + $data['fsize'] = 0;//formatsize($contaions['size']); + // $data['ffsize'] = lang('property_info_size', array('fsize' => formatsize($contaions['size']), 'size' => $contaions['size'])); + // $data['contain'] = lang('property_info_contain', array('filenum' => $contaions['contain'][0], 'foldernum' => $contaions['contain'][1])); + $data['img'] = $data['img']?$data['img']:'dzz/images/default/system/'.$data['flag'].'.png'; + } else { + $data['img'] = isset($data['img']) ? $data['img'] : geticonfromext($data['ext'], $data['type']); + } + if ($data['appid']) { + $imgs = C::t('app_market')->fetch_appico_by_appid($data['appid']); + $data['img'] = ($imgs) ? 'data/attachment/' . $imgs : geticonfromext($data['ext'], $data['type']); + } + if (empty($data['name'])) $data['name'] = $data['title']; + $data['url'] = isset($data['url']) ? replace_canshu($data['url']) : ''; + $data['ftype'] = getFileTypeName($data['type'], $data['ext']); + $data['fdateline'] = dgmdate($data['dateline'], 'Y-m-d H:i:s'); + $data['fsize'] = formatsize($data['size']); + $data['ffsize'] = lang('property_info_size', array('fsize' => formatsize($data['size']), 'size' => $data['size'])); + $data['relativepath'] = $data['path'] ? $data['path'] : ''; + $data['relpath'] = dirname(preg_replace('/dzz:(.+?):/', '', $data['relativepath'])) . '/'; + $data['path'] = $data['rid']; + $data['bz'] = ''; + $data['collect'] = C::t('resources_collect')->fetch_by_rid($rid); + if ($data['remote'] > 1) $data['rbz'] = io_remote::getBzByRemoteid($data['remote']); + + //增加安全相关的路径 + $data['dpath'] = dzzencode($data['path']); + $data['apath'] = $data['aid'] ? dzzencode('attach::' . $data['aid']) : $data['dpath']; + if (!$data['sperm']) $data['sperm'] = perm_FileSPerm::typePower($data['type'], $data['ext']); + Hook::listen('filter_resource_rid', $data);//数据过滤挂载点 + $this->store_cache($cachekey, $data); + return $data; + } + + /* //查询群组id + public function fetch_gid_by_rid($rid) + { + return DB::result_first("select gid from %t where rid = %d", array($this->_table, $rid)); + }*/ + + /* //查询多个文件右侧信息 + public function fetch_rightinfo_by_rid($rids) + { + if (!is_array($rids)) $rids = (array)$rids; + $fileinfo = array(); + $contains = array('size' => 0, 'contain' => array(0, 0)); + foreach (DB::fetch_all("select * from %t where rid in(%n)", array($this->_table, $rids)) as $value) { + $contains['size'] += $value['size']; + if ($value['type'] == 'folder') { + $contains['contain'][1] += 1; + $containchild = ''; + $containchild = $this->get_contains_by_fid($value['oid'], true); + if (!empty($containchild)) { + $contains['contain'][1] += $containchild['contain'][1]; + $contains['contain'][0] += $containchild['contain'][0]; + $contains['size'] += $containchild['size']; + } + + } else { + $contains['contain'][0] += 1; + } + if (!isset($fileinfo['path'])) { + $path = C::t('resources_path')->fetch_pathby_pfid($value['pfid']); + $fileinfo['position'] = preg_replace('/dzz:(.+?):/', '', $path); + } + + } + $fileinfo['ffsize'] = lang('property_info_size', array('fsize' => formatsize($contains['size']), 'size' => $contains['size'])); + $fileinfo['contain'] = lang('property_info_contain', array('filenum' => $contains['contain'][0], 'foldernum' => $contains['contain'][1])); + $fileinfo['filenum'] = count($rids); + return $fileinfo; + }*/ + + //查询目录文件数,$getversion =>是否获取版本数据 + public function get_contains_by_fid($fid, $getversion = true) + { + $contains = array('size' => 0, 'contain' => array(0, 0)); + $pfids = C::t('resources_path')->fetch_folder_containfid_by_pfid($fid); + + foreach (DB::fetch_all("select r.rid,r.vid,r.size as primarysize,r.type,r.pfid,v.size from %t r + left join %t v on r.rid=v.rid where r.pfid in (%n) and r.isdelete < 1", array($this->_table, 'resources_version', $pfids)) as $v) { + if (!isset($resluts[$v['rid']])) { + $resluts[$v['rid']] = $v; + } else { + $resluts[$v['rid']]['size'] += intval($v['size']); + } + } + foreach ($resluts as $value) { + if ($getversion) { + $contains['size'] += ($value['size'] > 0) ? $value['size'] : $value['primarysize']; + } else { + $contains['size'] += $value['primarysize']; + } + if ($value['type'] == 'folder' && $fid != $value['oid']) { + $contains['contain'][1] += 1; + } else { + $contains['contain'][0] += 1; + } + } + return $contains; + } + + //查询文件对应的rid + public function fetch_rid_by_fid($fid) + { + return DB::result_first("select rid from %t where oid = %d and `type` = 'folder' ", array($this->_table, $fid)); + } + + /* //查询文件夹对应的fid + public function fetch_fid_by_rid($rid) + { + return DB::result_first("select oid from %t where rid = %s and `type` = %s", array($this->_table, $rid, 'folder')); + }*/ + + //获取文件夹基本信息 + public function get_folderinfo_by_fid($fid) + { + if (!$folderinfo = C::t('folder')->fetch($fid)) return false; + /*$contaions = self::get_contains_by_fid($fid, true); + $folderinfo['ffsize'] = lang('property_info_size', array('fsize' => formatsize($contaions['size']), 'size' => $contaions['size'])); + $folderinfo['contain'] = lang('property_info_contain', array('filenum' => $contaions['contain'][0], 'foldernum' => $contaions['contain'][1]));*/ + $path = C::t('resources_path')->fetch_pathby_pfid($fid); + $folderinfo['position'] = preg_replace('/dzz:(.+?):/', '', $path); + $folderinfo['fdateline'] = dgmdate($folderinfo['dateline'], 'Y-m-d H:i:s'); + $folderinfo['isgroup'] = ($folderinfo['flag'] == 'organization') ? true : false; + return $folderinfo; + } + + //查詢文件夹下文件信息 + /*public function fetch_folderinfo_by_pfid($fid) + { + global $_G; + if ($fid) { + if ($folder = C::t('folder')->fetch($fid)) { + $where1 = array(); + if ($folder['gid'] > 0) { + $folder['perm'] = perm_check::getPerm($folder['fid']); + if ($folder['perm'] > 0) { + if (perm_binPerm::havePower('read2', $folder['perm'])) { + $where1[] = "1"; + } elseif (perm_binPerm::havePower('read1', $folder['perm'])) { + $where1[] = "uid='{$_G[uid]}'"; + } + + } + $where1 = array_filter($where1); + if (!empty($where1)) $temp[] = "(" . implode(' OR ', $where1) . ")"; + else $temp[] = "0"; + } else { + $temp[] = " uid='{$_G[uid]}'"; + } + $where[] = '(' . implode(' and ', $temp) . ')'; + unset($temp); + } + $wheresql = ""; + if ($where) $wheresql .= implode(' AND ', $where); + + return DB::fetch_all("select * from %t where pfid = %d and isdelete = 0 and $wheresql", array($this->_table, $fid)); + } + }*/ + + public function fetch_all_by_pfid($pfid, $conditions = array(), $limit = 0, $orderby = '', $order = '', $start = 0, $count = false) + { + global $_G; + $limitsql = $limit ? DB::limit($start, $limit) : ''; + $data = array(); + $wheresql = ' 1 '; + $where = array(); + $para = array($this->_table); + $where[] = ' isdelete < 1 '; + $mustdition = ''; + //解析搜索条件 + if ($conditions && is_string($conditions)) {//字符串条件语句 + $wheresql .= $conditions; + } elseif (is_array($conditions)) { + foreach ($conditions as $k => $v) { + if (!is_array($v)) { + if ($k == 'mustdition') { + $mustdition = $v; + } else { + $connect = 'and'; + $wheresql .= $connect . ' `' . $k . "` = '" . $v . "' "; + } + } else { + $relative = isset($v[1]) ? $v[1] : '='; + $connect = isset($v[2]) ? $v[2] : 'and'; + if ($relative == 'in') { + $wheresql .= $connect . " `" . $k . "` " . $relative . " (" . dimplode($v[0]) . ") "; + }elseif ($relative == 'not in') { + $wheresql .= $connect . " `" . $k . "` " . $relative . " (" . dimplode($v[0]) . ") "; + } elseif ($relative == 'stringsql') { + $wheresql .= $connect . " " . $v[0] . " "; + } elseif ($relative == 'like') { + $wheresql .= $connect . " " . $k . " like %s "; + $para[] = '%' . $v[0] . '%'; + } else { + $wheresql .= $connect . " `" . $k . "` " . $relative . " '" . $v[0] . "' "; + } + } + } + } + if (is_array($pfid)) { + $arr = array(); + foreach ($pfid as $fid) { + $temp = array('pfid = %d'); + $para[] = $fid; + if ($folder = C::t('folder')->fetch($fid)) { + $where1 = array(); + if ($folder['gid'] > 0) { + $folder['perm'] = perm_check::getPerm($folder['fid']); + if ($folder['perm'] > 0) { + if (perm_binPerm::havePower('read2', $folder['perm'])) { + $where1[] = "1"; + } elseif (perm_binPerm::havePower('read1', $folder['perm'])) { + $where1[] = "uid='{$_G[uid]}'"; + } + + } + $where1 = array_filter($where1); + if (!empty($where1)) $temp[] = "(" . implode(' OR ', $where1) . ")"; + else $temp[] = "0"; + } else { + $temp[] = " uid='{$_G[uid]}'"; + } + } + $arr[] = '(' . implode(' and ', $temp) . ')'; + unset($temp); + } + if ($arr) $where[] = '(' . implode(' OR ', $arr) . ')'; + } elseif ($pfid) { + $temp = array('pfid= %d'); + $para[] = $pfid; + if ($folder = C::t('folder')->fetch($pfid)) { + $where1 = array(); + if ($folder['gid'] > 0) { + $folder['perm'] = perm_check::getPerm($folder['fid']); + if ($folder['perm'] > 0) { + if (perm_binPerm::havePower('read2', $folder['perm'])) { + $where1[] = "1 = 1"; + } elseif (perm_binPerm::havePower('read1', $folder['perm'])) { + $where1[] = "uid='{$_G[uid]}'"; + } + } + $where1 = array_filter($where1); + if ($where1) $temp[] = "(" . implode(' OR ', $where1) . ")"; + else $temp[] = "0"; + } else { + $temp[] = " uid='{$_G[uid]}'"; + } + } + $where[] = '(' . implode(' and ', $temp) . ')'; + unset($temp); + } + if ($mustdition) $wheresql = '(' . $wheresql . $mustdition . ')'; + if ($where) $wheresql .= ' and ' . implode(' AND ', $where); + if ($count) return DB::result_first("SELECT COUNT(*) FROM %t $wheresql ", $para); + $ordersql = ''; + if (is_array($orderby)) { + foreach ($orderby as $key => $value) { + $orderby[$key] = $value . ' ' . $order; + } + $ordersql = ' ORDER BY ' . implode(',', $orderby); + } elseif ($orderby) { + if ($orderby == 'name') { + $ordersql = " ORDER BY convert(name,UNSIGNED) ".$order . + ",SUBSTRING_INDEX(name,'-',1) " . $order . ",convert(replace(replace(SUBSTRING_INDEX(name,'-',2),SUBSTRING_INDEX(name,'-',1),''),'-','') , UNSIGNED) " . $order . + ",convert(replace(replace(SUBSTRING_INDEX(name,'-',3),SUBSTRING_INDEX(name,'-',2),''),'-','') , UNSIGNED) " . $order; + } else { + $ordersql = ' ORDER BY ' . $orderby . ' ' . $order; + } + } + foreach (DB::fetch_all("SELECT rid FROM %t where $wheresql $ordersql $limitsql", $para) as $value) { + if ($arr = self::fetch_by_rid($value['rid'])) $data[$value['rid']] = $arr; + } + return $data; + } + + //查询群组下的文件、文件夹信息 + /*public function fetch_all_by_gid($gid) + { + $gid = intval($gid); + if ($folderinfo = C::t('folder')->fetch_folderinfo_by_gid($gid)) { + return self::fetch_by_pfid($folderinfo['fid']); + } + }*/ + + //查询目录下所有文件基本信息 + public function fetch_basicinfo_by_pfid($pfid) + { + $pfid = intval($pfid); + return DB::fetch_all("select * from %t where pfid = %d", array($this->_table, $pfid)); + } + + //查询目录下的文件信息 + public function fetch_by_pfid($pfid, $uid = '', $checkperm = true) + { + $currentuid = getglobal('uid'); + $pfid = intval($pfid); + $where = " pfid = %d"; + $param = array($this->_table, $pfid); + $datainfo = array(); + if ($uid) { + $where .= " and uid = %d"; + $param[] = $uid; + } + $path = C::t('resources_path')->fetch_pathby_pfid($pfid); + foreach (DB::fetch_all("select * from %t where $where and isdelete < 1 order by dateline desc", $param) as $k => $value) { + if ($value['type'] == 'folder') { + $value['path'] = $path . $value['name'] . '/';//路径 + if ($checkperm) { + if (!perm_check::checkperm_Container($value['oid'], 'read2') && + !($value['uid'] == $currentuid && perm_check::checkperm_Container($value['oid'], 'read1')) + ) { + continue; + } + } + } else { + if ($checkperm) { + $value['path'] = $path . $value['name'];//路径 + if (!perm_check::checkperm_Container($value['oid'], 'read2') && + !($value['uid'] == $currentuid) && perm_check::checkperm_Container($value['oid'], 'read1') + ) { + continue; + } + } + } + $data = C::t('resources_attr')->fetch_by_rid($value['rid'], $value['vid']); + $data['collect'] = C::t('resources_collect')->fetch_by_rid($value['rid']); + $datainfo[$k] = $value; + $datainfo[$k] = array_merge($datainfo[$k], $data); + if (!isset($datainfo[$k]['img'])) { + if ($datainfo[$k]['type'] == 'folder') { + $datainfo[$k]['img'] = './dzz/images/extimg/folder.png'; + } elseif ($datainfo[$k]['type'] == 'image') { + $datainfo[$k]['img'] = DZZSCRIPT . '?mod=io&op=thumbnail&size=small&path=' . dzzencode('attach::' . $datainfo[$k]['aid']); + } else { + $datainfo[$k]['img'] = './dzz/images/extimg/' . $datainfo[$k]['ext'] . '.png'; + } + } + $datainfo[$k]['taginfo'] = C::t('resources_tag')->fetch_tag_by_rid($value['rid']); + $datainfo[$k]['dpath'] = dzzencode($value['rid']); + $datainfo[$k]['fsize'] = formatsize($value['size']); + } + return $datainfo; + } + + //通过rid更新数据 + public function update_by_rid($rid, $setarr) + { + if (!is_array($rid)) $rid = (array)$rid; + if (parent::update($rid, $setarr)) { + foreach ($rid as $v) { + $cachekey = 'resourcesdata_' . $v; + $this->clear_cache($cachekey); + } + } + return true; + } + + //查询某目录下的所有文件夹 + public function fetch_folder_by_pfid($fid, $numselect = false) + { + + return DB::fetch_all("select * from %t where pfid = %d and `type` = %s and isdelete < 1 ", array($this->_table, $fid, 'folder')); + } + + public function fetch_folder_num_by_pfid($fid) + { + return DB::result_first("select count(*) from %t where pfid = %d and `type` = %s and deldateline < 1", array($this->_table, $fid, 'folder')); + } + + //通过rid获取属性信息 + public function get_property_by_rid($rids, $contains = true) + { + global $_G; + $uid = $_G['uid']; + $wheresql = " where r.rid in(%n) "; + $param = array($this->_table, 'folder', 'resources_path', $rids); + if (!is_array($rids)) $rids = (array)$rids; + if (count($rids) > 1) { + //获取文件基本信息 + $fileinfos = DB::fetch_all("select r.*,f.perm_inherit,p.path from %t r left join %t f on r.pfid = f.fid left join %t p on p.fid = r.pfid $wheresql", $param); + if (!$fileinfos) { + return array('error' => lang('no_privilege')); + } + $fileinfo = array(); + $tmpinfo = array(); + $infos = array(); + foreach ($fileinfos as $v) { + $infos[$v['rid']] = $v; + $tmpinfo['rids'][] = $v['rid']; + $tmpinfo['names'][] = $v['name']; + $tmpinfo['pfid'][] = $v['pfid']; + $tmpinfo['ext'][] = ($v['ext']) ? $v['ext'] : $v['type']; + $tmpinfo['type'][] = $v['type']; + $tmpinfo['username'][] = $v['username']; + $tnpinfo['hascontain'][$v['rid']] = ($v['type'] == 'folder') ? 1 : 0; + $tmpinfo['realpath'][] = $v['path']; + } + $fileinfo['ismulti'] = count($rids);//是否是多选 + $fileinfo['name'] = getstr(implode(',', array_unique($tmpinfo['names'])), 60); + //判断文件归属 + $fileinfo['username'] = (count(array_unique($tmpinfo['username'])) > 1) ? lang('more_member_owner') : $tmpinfo['username'][0]; + + //判断是否在同一文件夹下 + if (count(array_unique($tmpinfo['pfid'])) > 1) { + $fileinfo['realpath'] = lang('more_folder_position'); + $fileinfo['rid'] = implode(',', $tmpinfo['rids']); + } else { + $fileinfo['realpath'] = lang('all_positioned') . preg_replace('/dzz:(.+?):/', '', $tmpinfo['realpath'][0]); + $fileinfo['rid'] = implode(',', $tmpinfo['rids']); + } + //判断文件类型是否相同 + $judgesecond = false; + if (count(array_unique($tmpinfo['ext'])) > 1) { + $fileinfo['type'] = lang('more_file_type'); + $judgesecond = true; + + } else { + $fileinfo['type'] = lang('louis_vuitton') . $tmpinfo['ext'][0] . lang('type_of_file'); + } + if (in_array('', $tmpinfo['ext']) || $judgesecond) { + if (count(array_unique($tmpinfo['type'])) > 1) { + $fileinfo['type'] = lang('more_file_type'); + } else { + $fileinfo['type'] = lang('louis_vuitton') . $tmpinfo['type'][0] . lang('typename_attach'); + } + } + + if ($contains) { + //文件大小和文件个数信息 + $tmpinfo['contains'] = array('size' => 0, 'contain' => array(0, 0)); + foreach ($tnpinfo['hascontain'] as $k => $v) { + if ($v) { + $tmpinfo['contains']['contain'][1] += 1; + $childcontains = self::get_contains_by_fid($infos[$k]['oid'], true); + $tmpinfo['contains']['contain'][0] += $childcontains['contain'][0]; + $tmpinfo['contains']['contain'][1] += $childcontains['contain'][1]; + $tmpinfo['contains']['size'] += $childcontains['size']; + } else { + $tmpinfo['contains']['contain'][0] += 1; + $tmpinfo['contains']['size'] += $infos[$k]['size']; + } + } + $fileinfo['fsize'] = formatsize($tmpinfo['contains']['size']); + $fileinfo['ffsize'] = lang('property_info_size', array('fsize' => formatsize($tmpinfo['contains']['size']), 'size' => $tmpinfo['contains']['size'])); + $fileinfo['contain'] = lang('property_info_contain', array('filenum' => $tmpinfo['contains']['contain'][0], 'foldernum' => $tmpinfo['contains']['contain'][1])); + } + $fileinfo['img'] = self::get_icosinfo_by_rid($fileinfo['rid']); + + unset($tmpinfo); + } else {//单个文件信息 + //文件基本信息 + $fileinfo = DB::fetch_first("select r.*,f.perm_inherit,p.path from %t r + left join %t f on r.pfid = f.fid left join %t p on r.pfid = p.fid $wheresql", $param); + + if (!$fileinfo) { + return array('error' => lang('no_privilege')); + } + //文件统计信息 + $filestatis = C::t('resources_statis')->fetch_by_rid($rids[0]); + //位置信息 + $fileinfo['realpath'] = preg_replace('/dzz:(.+?):/', '', $fileinfo['path']); + + + //统计信息 + $fileinfo['opendateline'] = ($filestatis['opendateline']) ? dgmdate($filestatis['opendateline'], 'Y-m-d H:i:s') : dgmdate($fileinfo['dateline'], 'Y-m-d H:i:s'); + $fileinfo['editdateline'] = ($filestatis['editdateline']) ? dgmdate($filestatis['editdateline'], 'Y-m-d H:i:s') : dgmdate($fileinfo['dateline'], 'Y-m-d H:i:s'); + $fileinfo['fdateline'] = dgmdate($fileinfo['dateline'], 'Y-m-d H:i:s'); + //编辑权限信息 + $fileinfo['editperm'] = 1; + if ($fileinfo['gid'] > 0) { + $powerarr = perm_binPerm::getPowerArr(); + if (!(C::t('organization_admin')->chk_memberperm($fileinfo['gid'])) && !($uid == $fileinfo['uid'] && $fileinfo['perm_inherit'] & $powerarr['edit1']) && !($fileinfo['perm_inherit'] & $powerarr['edit2'])) { + $fileinfo['editperm'] = 0; + } + } + + //文件图标信息 + $fileinfo['img'] = self::get_icosinfo_by_rid($fileinfo['rid']); + if ($fileinfo['type'] == 'folder') { + $fileinfo['type'] = '文件夹'; + if ($currentfolder = C::t('folder')->fetch($fileinfo['oid'])) { + $fileinfo['isgroup'] = ($currentfolder['flag'] == 'organization') ? true : false; + } + } elseif ($fileinfo['ext']) { + $fileinfo['type'] = $fileinfo['ext'] . lang('typename_folder'); + } else { + $fileinfo['type'] = lang('undefined_file_type'); + } + if ($contains) { + //文件大小信息 + if ($fileinfo['type'] == 'folder') { + $contaions = self::get_contains_by_fid($fileinfo['oid'], true); + $contaions['contain'][1] += 1; + $fileinfo['fsize'] = formatsize($contaions['size']); + $fileinfo['ffsize'] = lang('property_info_size', array('fsize' => formatsize($contaions['size']), 'size' => $contaions['size'])); + $fileinfo['contain'] = lang('property_info_contain', array('filenum' => $contaions['contain'][0], 'foldernum' => $contaions['contain'][1])); + } elseif ($fileinfo['ext']) { + $fileinfo['fsize'] = formatsize($fileinfo['size']); + } else { + $fileinfo['fsize'] = formatsize($fileinfo['size']); + } + + } + } + + return $fileinfo; + } + + public function get_containsdata_by_rid($rids) + { + $fileinfo = array(); + if (!is_array($rids)) $rids = (array)$rids; + if (count($rids) > 1) { + $fileinfos = DB::fetch_all("select `type`,oid,rid,size from %t where rid in(%n)", array($this->_table, $rids)); + $fileinfo = array(); + $tmpinfo = array(); + $infos = array(); + foreach ($fileinfos as $v) { + $infos[$v['rid']] = $v; + $tnpinfo['hascontain'][$v['rid']] = ($v['type'] == 'folder') ? 1 : 0; + } + $tmpinfo['contains'] = array('size' => 0, 'contain' => array(0, 0)); + foreach ($tnpinfo['hascontain'] as $k => $v) { + if ($v) { + $tmpinfo['contains']['contain'][1] += 1; + $childcontains = self::get_contains_by_fid($infos[$k]['oid'], true); + $tmpinfo['contains']['contain'][0] += $childcontains['contain'][0]; + $tmpinfo['contains']['contain'][1] += $childcontains['contain'][1]; + $tmpinfo['contains']['size'] += $childcontains['size']; + } else { + $tmpinfo['contains']['contain'][0] += 1; + $tmpinfo['contains']['size'] += $infos[$k]['size']; + } + } + $fileinfo['fsize'] = formatsize($tmpinfo['contains']['size']); + $fileinfo['ffsize'] = lang('property_info_size', array('fsize' => formatsize($tmpinfo['contains']['size']), 'size' => $tmpinfo['contains']['size'])); + $fileinfo['contain'] = lang('property_info_contain', array('filenum' => $tmpinfo['contains']['contain'][0], 'foldernum' => $tmpinfo['contains']['contain'][1])); + }else{ + $fileinfo = $this->fetch($rids[0]); + //文件类型和大小信息 + if ($fileinfo['type'] == 'folder') { + $contaions = self::get_contains_by_fid($fileinfo['oid'], true); + $contaions['contain'][1] += 1; + $fileinfo['fsize'] = formatsize($contaions['size']); + $fileinfo['ffsize'] = lang('property_info_size', array('fsize' => formatsize($contaions['size']), 'size' => $contaions['size'])); + $fileinfo['contain'] = lang('property_info_contain', array('filenum' => $contaions['contain'][0], 'foldernum' => $contaions['contain'][1])); + } elseif ($fileinfo['ext']) { + $fileinfo['fsize'] = formatsize($fileinfo['size']); + $fileinfo['contain'] = lang('property_info_contain', array('filenum' => 1, 'foldernum' =>0)); + } else { + $fileinfo['fsize'] = formatsize($fileinfo['size']); + $fileinfo['contain'] = lang('property_info_contain', array('filenum' => 1, 'foldernum' =>0)); + } + } + return $fileinfo; + + +} + public function get_containsdata_by_fid($fid){ + $fileinfo = array(); + if($fid){ + $contaions = self::get_contains_by_fid($fid, true); + $fileinfo['fsize'] = lang('property_info_size', array('fsize' => formatsize($contaions['size']), 'size' => $contaions['size'])); + $fileinfo['contain'] = lang('property_info_contain', array('filenum' => $contaions['contain'][0], 'foldernum' => $contaions['contain'][1])); + } + return $fileinfo; + } + +//根据fid获取属性信息 +public function get_property_by_fid($fid, $contains = true) +{ + global $_G; + $uid = $_G['uid']; + $fileinfo = array(); + $param = array('folder', 'resources_path', $fid); + $folders = DB::fetch_first("select f.*,p.path from %t f left join %t p on f.fid = p.fid where f.fid = %d ", $param); + if (!$folders) { + return array('error' => lang('no_privilege')); + } + $fileinfo['realpath'] = preg_replace('/dzz:(.+?):/', '', $folders['path']); + $fileinfo['name'] = $folders['fname']; + $fileinfo['username'] = $folders['username']; + if ($folders['gid'] > 0 && $folders['pfid'] == 0) { + $fileinfo['type'] = lang('org_or_group'); + } else { + $fileinfo['type'] = lang('type_folder'); + } + if ($contains) { + $contaions = self::get_contains_by_fid($fid, true); + $fileinfo['fsize'] = lang('property_info_size', array('fsize' => formatsize($contaions['size']), 'size' => $contaions['size'])); + $fileinfo['contain'] = lang('property_info_contain', array('filenum' => $contaions['contain'][0], 'foldernum' => $contaions['contain'][1])); + } + + //编辑权限信息 + if ($folders['gid'] > 0) { + $powerarr = perm_binPerm::getPowerArr(); + if (!($uid == $folders['uid'] && $folders['perm_inherit'] & $powerarr['edit1']) && !($folders['perm_inherit'] & $powerarr['edit2'])) { + $fileinfo['editperm'] = 0; + } else { + $fileinfo['editperm'] = 1; + } + } else { + $fileinfo['editperm'] = 1; + } + $statis = C::t('resources_statis')->fetch_by_fid($fid); + $fileinfo['opendateline'] = ($statis['opendateline']) ? dgmdate($statis['opendateline'], 'Y-m-d H:i:s') : ''; + $fileinfo['editdateline'] = ($statis['editdateline']) ? dgmdate($statis['editdateline'], 'Y-m-d H:i:s') : ''; + $fileinfo['fdateline'] = ($folders['dateline']) ? dgmdate($folders['dateline'], 'Y-m-d H:i:s') : ''; + return $fileinfo; + +} + +public +function get_icosinfo_by_rid($rid) +{ + $resourcedata = parent::fetch($rid); + $attrdata = C::t('resources_attr')->fetch_by_rid($rid, $resourcedata['vid']); + $data = array_merge($resourcedata, $attrdata); + if ($data['type'] == 'image') { + $data['img'] = DZZSCRIPT . '?mod=io&op=thumbnail&size=small&path=' . dzzencode('attach::' . $data['aid']); + } elseif ($data['type'] == 'attach' || $data['type'] == 'document') { + $data['img'] = geticonfromext($data['ext'], $data['type']); + } elseif ($data['type'] == 'shortcut') { + $data['img'] = isset($data['tdata']['img']) ? $data['tdata']['img'] : geticonfromext($data['tdata']['ext'], $data['tdata']['type']); + } elseif ($data['type'] == 'dzzdoc') { + + $data['img'] = isset($data['img']) ? $data['img'] : geticonfromext($data['ext'], $data['type']); + } elseif ($data['type'] == 'folder') { + $data['img'] = $data['img']?$data['img']:'dzz/images/default/system/'.$data['flag'].'.png'; + } else { + $data['img'] = isset($data['img']) ? $data['img'] : geticonfromext($data['ext'], $data['type']); + } + $img = $data['img']; + unset($data); + return $img; +} + +//文件名获取文件信息 +public +function get_resources_by_pfid_name($pfid, $name) +{ + return DB::fetch_first("select * from %t where pfid=%d and name = %s and `type` = 'folder' ", array($this->_table, $pfid, $name)); +} + +//文件id获取文件信息 +public +function get_resources_info_by_fid($fid) +{ + return DB::fetch_first("select * from %t where oid = %d and `type` = 'folder' ", array($this->_table, $fid)); +} +} \ No newline at end of file diff --git a/core/class/table/table_resources_attr.php b/core/class/table/table_resources_attr.php new file mode 100644 index 0000000..139a80e --- /dev/null +++ b/core/class/table/table_resources_attr.php @@ -0,0 +1,123 @@ +_table = 'resources_attr'; + $this->_pk = 'id'; + $this->_pre_cache_key = 'resources_attr_'; + $this->_cache_ttl = 60 * 60; + parent::__construct(); + } + public function delete_by_id($id){ + if(!$data=parent::fetch($id)) return false; + if($ret=parent::delete($id)){ + if($data['skey']=='icon' && $data['sval']>0){ + C::t('attachment')->delete_by_aid($data['sval']); + } + $cachekey = 'resources_attr_data_'.$data['rid'].$data['vid']; + $this->clear_cache($cachekey); + } + return $ret; + } + public function update($id,$setarr){ + if(!$data=parent::fetch($id)) return false; + if($ret=parent::update($id,$setarr)){ + if($setarr['skey']=='icon'){ + if($data['sval']) C::t('attachment')->delete_by_aid($data['sval']); + if($setarr['sval']) C::t('attachment')->addcopy_by_aid($setarr['sval']); + $cachekey = 'resources_attr_data_'.$data['rid'].$data['vid']; + $this->clear_cache($cachekey); + } + } + return $ret; + } + public function insert($setarr){ + if($id=DB::result_first("select id from %t where rid=%s and skey=%s and vid=%d",array($this->_table,$setarr['rid'],$setarr['skey'],intval($setarr['vid'])))){ + if($setarr['skey']=='icon'){ + $o=parent::fetch($id); + } + $ret=self::update($id,$setarr); + }else{ + if($id=parent::insert($setarr,1)){ + $cachekey = 'resources_attr_data_'.$setarr['rid'].$setarr['vid']; + $this->clear_cache($cachekey); + } + } + //处理图标 + if($id && $setarr['skey']=='icon'){ + if($o['sval']) C::t('attachment')->delete_by_aid($o['sval']); + if($setarr['sval']) C::t('attachment')->addcopy_by_aid($setarr['sval']); + } + return $id; + } + public function fetch_by_rid($rid,$vid = 0){ + $cachekey = 'resources_attr_data_'.$rid.$vid; + if($returndata = $this->fetch_cache($cachekey)){ + return $returndata; + } + $returndata = array(); + foreach(DB::fetch_all("select * from %t where rid = %s and vid = %d",array($this->_table,$rid,$vid)) as $val ){ + if($val['skey']=='icon'){ + $val['sval']=C::t('attachment')->getThumbByAid($val['sval'],0,0,1); + $val['skey']='img'; + } + $returndata[$val['skey']] = $val['sval']; + } + $this->store_cache($cachekey,$returndata); + return $returndata; + } + public function insert_attr($rid,$vid=0,$attrs=array()){ + $i = 0; + foreach($attrs as $k=>$v){ + $setarr=array('rid'=>$rid,'skey'=>$k,'vid'=>$vid,'sval'=>$v); + if(self::insert($setarr)){ + $i++; + } + } + return $i; + } + public function delete_by_rvid($rid,$vid){ + $i=0; + foreach(DB::fetch_all("select id from %t where rid=%s and vid=%d",array($this->_table,$rid,$vid)) as $value){ + if(self::delete_by_id($value['id'])){ + $i++; + } + } + return $i; + } + public function delete_by_rid($rid){ + if(!is_array($rid)) $rid = (array)$rid; + $i=0; + foreach(DB::fetch_all("select id from %t where rid IN(%n) ",array($this->_table,$rid)) as $value){ + if(self::delete_by_id($value['id'])){ + $i++; + } + } + return $i; + } + + public function update_by_skey($rid,$vid,$skeyarr){ + $i=0; + foreach($skeyarr as $k=>$v){ + $setarr=array('rid'=>$rid,'skey'=>$k,'vid'=>$vid,'sval'=>$v); + if(self::insert($setarr)){ + $i++; + } + } + return $i; + } + public function update_vid_by_rvid($rid,$oldvid,$vid){ + $i=0; + foreach(DB::fetch_all("select id from %t where rid=%s and vid = %d",array($this->_table,$rid,$oldvid)) as $value){ + if(self::update($value['id'],array('vid'=>$vid))){ + $i++; + } + } + return $i; + } +} \ No newline at end of file diff --git a/core/class/table/table_resources_cat.php b/core/class/table/table_resources_cat.php new file mode 100644 index 0000000..96e198f --- /dev/null +++ b/core/class/table/table_resources_cat.php @@ -0,0 +1,83 @@ +_table = 'resources_cat'; + $this->_pk = 'id'; + parent::__construct(); + } + //添加搜索类型 + public function insert_cat($setarr){ + //搜索类型同一用户不能重名 + if(DB::result_first("select count(*) from %t where catname = %s and uid = %d",array($this->_table,$setarr['catname'],$setarr['uid'])) > 0){ + return array('error'=>true,'msg'=>lang('exploder_name_repeat')); + } + //处理标签数据 + if(isset($setarr['tag'])){ + $setarr['tag'] = explode(',',$setarr['tag']); + //将标签放入标签表,如果有并且为该应用下,则自动增加使用数 + $tagdata = C::t('tag')->insert_data($setarr['tag'],'explorer'); + $tags = ''; + foreach($tagdata as $v){ + $tags .= $v['tid'].','; + } + $setarr['tag'] = substr($tags,0,-1); + } + if($insertid = parent::insert($setarr,1)){ + return array('success'=>true,'insert'=>$insertid); + } + return array('error'=>true,'msg'=>lang('exploder_add_failed')); + } + + public function update($catid,$setarr){ + if(!$catinfo = parent::fetch($catid)) return false; + if(isset($setarr['tag'])){ + $oldtids = explode(',',$catinfo['tag']); + $setarr['tag'] = array_filter(explode(',',$setarr['tag'])); + if(!empty($setarr['tag'])){ + //将标签放入标签表,如果有并且为该应用下,则自动增加使用数 + $tagdata = C::t('tag')->insert_data($setarr['tag'],'explorer'); + $tags = ''; + foreach($tagdata as $v){ + $tags .= $v['tid'].','; + $newtids[] = $v['tid']; + } + $setarr['tag'] = substr($tags,0,-1); + }else{ + $setarr['tag'] = ''; + } + C::t('tag')->addhot_by_tid($oldtids,-1); + } + return parent::update($catid,$setarr); + } + //查询搜索类型 + public function fetch_by_id($id){ + $id = intval($id); + return parent::fetch($id); + } + //删除搜索类型 + public function del_by_id($id){ + $id = intval($id); + if(!$cat = parent::fetch($id)){ + return false; + } + if($cat['dafault'] == 1){//系统默认不能删除 + return false; + } + return parent::delete($id); + } + public function fetch_by_uid($uid){ + return DB::fetch_all("select * from %t where uid = %d order by `default` desc",array($this->_table,$uid)); + } + //查询当前数据最近的一条 + public function fetch_rencent_id($id){ + global $_G; + return DB::result_first("select id from %t where id < %d and uid = %d order by id desc",array($this->_table,$id,$_G['uid'])); + } + +} \ No newline at end of file diff --git a/core/class/table/table_resources_clipboard.php b/core/class/table/table_resources_clipboard.php new file mode 100644 index 0000000..26a8795 --- /dev/null +++ b/core/class/table/table_resources_clipboard.php @@ -0,0 +1,113 @@ +_table = 'resources_clipboard'; + $this->_pk = 'id'; + parent::__construct(); + } + //$copytype默认值为1,为1是复制,为2是剪切 + public function insert_data($paths,$copytype = 1){ + $uid = getglobal('uid'); + if(!is_array($paths)) $paths = (array)$paths; + $rids = ''; + $typearr = array(); + foreach(DB::fetch_all("select rid,uid,pfid,gid,oid,`type` from %t where rid in (%n) and isdelete < 1",array('resources',$paths)) as $v){ + $pfid = $v['pfid']; + if($copytype == 1){ + if($v['type'] == 'folder'){ + $return = C::t('resources')->check_folder_perm($v,'copy'); + if($return['error']) return array('error'=>$return['error']); + $typearr[] = 1; + }else{ + if (!perm_check::checkperm_Container($pfid, 'copy2') && !($uid == $v['uid'] && perm_check::checkperm_Container($pfid, 'copy1'))) { + return array('error'=>lang('no_privilege')); + } + $typearr[] = 2; + } + }else{ + if($v['type'] == 'folder'){ + $return = C::t('resources')->check_folder_perm($v,'cut'); + if($return['error']) return array('error'=>$return['error']); + $typearr[] = 1; + }else{ + if (!perm_check::checkperm_Container($pfid, 'delete2') && !($uid == $v['uid'] && perm_check::checkperm_Container($pfid, 'delete1'))) { + return array('error'=>lang('no_privilege')); + } + $typearr[] = 2; + } + } + $rids .= $v['rid'].','; + } + $typearr = array_unique($typearr); + if(count($typearr) > 1){ + $type = 3; + }else{ + $type = $typearr[0]; + } + if(!$rids) return array('error'=>lang('no_privilege')); + + $rids = substr($rids,0,-1); + $setarr = array( + 'uid'=>getglobal('uid'), + 'username'=>getglobal('username'), + 'dateline'=>time(), + 'type'=>$type, + 'files'=>$rids, + 'copytype'=>$copytype + ); + self::delete_by_uid(); + if($copyid = parent::insert($setarr,1)){ + return array('rid'=>$rids,'copyid'=>$copyid,'type'=>$type); + } + return array('error'=>lang('sysem_busy')); + } + + public function delete_by_uid(){ + $uid = getglobal('uid'); + if(DB::result_first("select count(*) from %t where uid = %d",array($this->_table,$uid)) > 0){ + return DB::delete($this->_table,array('uid'=>$uid)); + } + } + public function fetch_by_uid(){ + $uid = getglobal('uid'); + if($return = DB::fetch_first("select * from %t where uid = %d",array($this->_table,$uid))){ + return $return; + } + return false; + } + public function fetch_user_paste_type(){ + $uid = getglobal('uid'); + return DB::result_first("select `type` from %t where uid = %d",array($this->_table,$uid)); + } + //去掉粘贴板已删除的rid + public function update_data_by_delrid($rids) + { + if (!is_array($rids)) $rids = (array)$rids; + if(empty($rids)) return ; + $datas = array(); + foreach ($rids as $v) { + foreach (DB::fetch_all("select id,files from %t where find_in_set(%s,files)", array($this->table, $v)) as $val) { + if($val['files']){ + $files = explode(',', $val['files']); + $key = array_search($v,$files); + unset($files[$key]); + if(empty($files)){ + parent::delete($val['id']); + }else{ + $files = implode(',', $files); + parent::update($val['id'],array('files' => $files)); + } + } + + } + + } + return true; + } +} \ No newline at end of file diff --git a/core/class/table/table_resources_collect.php b/core/class/table/table_resources_collect.php new file mode 100644 index 0000000..1b8ca0e --- /dev/null +++ b/core/class/table/table_resources_collect.php @@ -0,0 +1,138 @@ +_table = 'resources_collect'; + $this->_pk = 'id'; + parent::__construct(); + } + public function add_collect_by_rid($rids){ + global $_G; + if(!is_array($rids)) $rids = (array)$rids; + $i = 0; + $arr = array(); + foreach($rids as $v){ + //获取收藏文件基本信息 + if($data = C::t('resources')->fetch_info_by_rid($v,true)){ + $setarr = array( + 'rid'=>$v, + 'uid'=>$_G['uid'], + 'username'=>$_G['username'], + 'dateline'=>time(), + 'pfid'=>$data['pfid'] + ); + if (!perm_check::checkperm_Container($data['pfid'], 'read2') && !($_G['uid'] == $data['uid'] && perm_check::checkperm_Container($data['pfid'], 'read1'))) { + continue; + } + if(self::add_collect($setarr)){ + //处理数据 + $arr['msg'][$v]='success'; + $ridarr[]= $v; + $i++; + }else{ + $arr['msg'][$v]=array('error'=>lang('explorer_do_failed')); + } + }else{ + continue; + } + + } + return $arr; + } + public function add_collect($setarr){ + //如果已经加入收藏,不允许重复收藏 + if(DB::result_first("select id from %t where rid = %s and uid = %d",array($this->_table,$setarr['rid'],$setarr['uid']))){ + return false; + } + //加入收藏 + if($insert = parent::insert($setarr,1)){ + return $insert; + }else{ + return false; + } + } + //取消当前用户收藏的某文件 + public function cancle_clooect_by_rid_uid($rid,$uid){ + if(!$collectinfo = DB::fetch_first("select * from %t where rid = %s",array($this->_table,$rid))){ + return array('error'=>lang('collect_file_not_exists')); + } + if($collectinfo['uid'] != $uid){ + return array('error'=>lang('no_privilege')); + } + if(DB::delete($this->_table,array('rid'=>$rid,'uid'=>$uid))){ + $fileinfo = C::t('resources')->fetch_info_by_rid($rid); + return array('success'=>true,'rid'=>$rid,'name'=>$fileinfo['name']); + } + } + //删除当前用户对某些文件的收藏 + public function delete_usercollect_by_rid($rids){ + if(!is_array($rids)) $rids = (array)$rids; + $uid = getglobal('uid'); + $i=0; + $return = array(); + foreach($rids as $v){ + $return = self::cancle_clooect_by_rid_uid($v,$uid); + if(!isset($return['error'])){ + //处理数据 + $arr['msg'][$return['rid']]='success'; + $ridarr[]= $return['rid']; + $i++; + }else{ + $arr['msg'][$return['rid']]=$return['error']; + } + } + + return $arr; + } + //删除某文件的收藏 + public function delete_by_rid($rid){ + if(!is_array($rid)) $rid = (array)$rid; + if(!$collectinfo = DB::fetch_first("select * from %t where rid in (%n)",array($this->_table,$rid))){ + return array('error'=>lang('collect_file_not_exists')); + } + if(DB::delete($this->_table,'rid in('.dimplode($rid).')')){ + return true; + } + return false; + } + //清空当前用户的所有收藏 + public function delete_by_uid(){ + $uid = getglobal('uid'); + if(DB::delete($this->_table,array('uid'=>$uid))){ + return true; + }else{ + return false; + } + } + //查询当前用户所有收藏 + public function fetch_by_uid($limitsql = '',$ordersql = ''){ + $uid = getglobal('uid'); + if($return = DB::fetch_all("select * from %t where uid = %d $ordersql $limitsql",array($this->_table,$uid))){ + return $return; + }else{ + return false; + } + } + public function fetch_rid_by_uid(){ + $uid = getglobal('uid'); + if($return = DB::fetch_all("select rid from %t where uid = %d",array($this->_table,$uid))){ + return $return; + }else{ + return false; + } + } + public function fetch_by_rid($rid){ + $rid = trim($rid); + $uid = getglobal('uid'); + if(DB::result_first("select count(*) from %t where uid = %d and rid = %s",array($this->_table,$uid,$rid))){ + return true; + }else{ + return false; + } + } +} \ No newline at end of file diff --git a/core/class/table/table_resources_event.php b/core/class/table/table_resources_event.php new file mode 100644 index 0000000..733e84a --- /dev/null +++ b/core/class/table/table_resources_event.php @@ -0,0 +1,469 @@ +_table = 'resources_event'; + $this->_pk = 'id'; + + parent::__construct(); + } + + //添加群组动态 + public function addevent_by_pfid($pfid, $event, $do, $eventdata, $gid = '', $rid = '', $do_obj = '', $type = 0) + { + if (!$pfid) return false; + $eventArr = array( + 'rid' => $rid, + 'event_body' => $event, + 'uid' => getglobal('uid'), + 'username' => getglobal('username'), + 'dateline' => time(), + 'body_data' => serialize($eventdata), + 'gid' => $gid, + 'pfid' => $pfid, + 'do' => $do, + 'do_obj' => $do_obj, + 'type' => $type + ); + if ($insert = parent::insert($eventArr, 1)) { + return $insert; + } else { + return false; + } + } + + public function delete_by_gid($gid) + { + DB::delete($this->table, array('gid' => $gid)); + } + + //删除文件夹动态,仅限于文件夹,其下文件动态不删除 + public function delete_by_pfid_and_notrid($fid) + { + return DB::delete($this->_table, array('rid' => '', 'pfid' => $fid)); + } + + //删除动态 + public function delete_by_rid($rid) + { + if (!is_array($rid)) $rid = (array)$rid; + if (DB::delete($this->_table, 'rid in(' . dimplode($rid) . ')')) { + return array('success' => lang('exploder_do_succeed')); + } + return array('error' => lang('exploder_do_failed')); + + } + + //更改动态归属位置信息(移动文件时使用) + public function update_position_by_rid($rid, $pfid, $gid) + { + if (!is_array($rid)) $rid = (array)$rid; + DB::update($this->_table, array('pfid' => $pfid, 'gid' => $gid), "rid IN(" . dimplode($rid) . ")"); + return true; + } + + public function fetch_event_by_gid($gid) + { + $gid = intval($gid); + $time = date('Y-m-d'); + $starttime = strtotime($time); + $endtime = $starttime + 3600 * 24; + $events = array(); + foreach (DB::fetch_all("select * from %t where gid = %d and dateline > %d and dateline < %d order by dateline desc", array($this->_table, $gid, $starttime, $endtime)) as $v) { + $v['body_data'] = unserialize($v['body_data']); + $v['body_data']['msg'] = self::emoji_decode($v['body_data']['msg']); + $v['body_data']['msg'] = preg_replace_callback("/@\[(.+?):(.+?)\]/i", "atreplacement", $v['body_data']['msg']); + $v['body_data']['msg'] = dzzcode($v['body_data']['msg']); + $v['do_lang'] = lang($v['do']); + $v['details'] = lang($v['event_body'], $v['body_data']); + + $events[] = $v; + } + return $events; + } + + public function emoji_decode($str) + { + $text = json_encode($str); //暴露出unicode + $text = preg_replace_callback('/\\\\\\\\/i', function ($str) { + return '\\'; + }, $text); //将两条斜杠变成一条,其他不动 + return json_decode($text); + } + + //根据fid查询评论 + public function fetch_comment_by_fid($fid, $count = false, $start = 0, $limit = 0) + { + $fid = intval($fid); + $params = array($this->_table, $fid, 1); + $limitsql = $limit ? DB::limit($start, $limit) : ''; + if ($count) { + return DB::result_first("select count(*) from %t where pfid = %d and rid = '' and `type`= %d", $params); + } + $events = array(); + foreach (DB::fetch_all("select * from %t where pfid = %d and rid = '' and `type`= %d order by dateline desc $limitsql", $params) as $v) { + $v['body_data'] = unserialize($v['body_data']); + $v['body_data']['msg'] = self::emoji_decode($v['body_data']['msg']); + $v['body_data']['msg'] = preg_replace_callback("/@\[(.+?):(.+?)\]/i", "atreplacement", $v['body_data']['msg']); + $v['body_data']['msg'] = dzzcode($v['body_data']['msg']); + $v['do_lang'] = lang($v['do']); + $v['details'] = lang($v['event_body'], $v['body_data']); + $v['fdate'] = dgmdate($v['dateline'], 'u'); + $uids[] = $v['uid']; + $events[] = $v; + } + if (count($events)) { + $events = self::result_events_has_avatarstatusinfo($uids, $events); + } + + + return $events; + } + + //根据fid查询评论 + public function fetch_comment_by_rid($rid, $count = false, $start = 0, $limit = 0) + { + $rid = trim($rid); + $params = array($this->_table, $rid, 1); + $limitsql = $limit ? DB::limit($start, $limit) : ''; + if ($count) { + return DB::result_first("select count(*) from %t where rid = %s and `type`= %d", $params); + } + $uid = array(); + $events = array(); + foreach (DB::fetch_all("select * from %t where rid = %s and `type`= %d order by dateline desc $limitsql", $params) as $v) { + $v['body_data'] = unserialize($v['body_data']); + $v['body_data']['msg'] = self::emoji_decode($v['body_data']['msg']); + $v['body_data']['msg'] = preg_replace_callback("/@\[(.+?):(.+?)\]/i", "atreplacement", $v['body_data']['msg']); + $v['body_data']['msg'] = dzzcode($v['body_data']['msg']); + $v['do_lang'] = lang($v['do']); + $v['details'] = lang($v['event_body'], $v['body_data']); + $v['fdate'] = dgmdate($v['dateline'], 'u'); + $uids[] = $v['uid']; + $events[] = $v; + } + if (count($events)) { + $events = self::result_events_has_avatarstatusinfo($uids, $events); + } + + return $events; + } + + //根据rid查询动态 + public function fetch_by_rid($rids, $start = 0, $limit = 0, $count = false, $type = false) + { + if (!is_array($rids)) $rids = (array)$rids; + $fids = array(); + foreach (DB::fetch_all("select * from %t where rid in(%n)", array('resources', $rids)) as $v) { + if ($v['type'] == 'folder') { + $fids[] = $v['oid']; + } + } + $wheresql = " where rid in(%n) "; + $params = array($this->_table, $rids); + if (count($fids) > 0) { + $wheresql .= " or (pfid in(%n))"; + $params[] = $fids; + } + if ($type) { + $type = $type - 1; + $wheresql .= ' and `type` = ' . $type; + } + if ($count) { + return DB::result_first("select count(*) from %t $wheresql", $params); + } + $limitsql = $limit ? DB::limit($start, $limit) : ''; + $events = array(); + $uids = array(); + foreach (DB::fetch_all("select * from %t $wheresql order by dateline desc $limitsql", $params) as $v) { + $v['body_data'] = unserialize($v['body_data']); + $v['body_data']['msg'] = self::emoji_decode($v['body_data']['msg']); + $v['body_data']['msg'] = preg_replace_callback("/@\[(.+?):(.+?)\]/i", "atreplacement", $v['body_data']['msg']); + $v['body_data']['msg'] = dzzcode($v['body_data']['msg']); + $v['do_lang'] = lang($v['do']); + $v['details'] = lang($v['event_body'], $v['body_data']); + $v['fdate'] = dgmdate($v['dateline'], 'u'); + $uids[] = $v['uid']; + $events[] = $v; + } + $events = self::result_events_has_avatarstatusinfo($uids, $events); + + return $events; + } + + //根据文件夹id查询动态 + public function fetch_by_pfid_rid($fid, $counts = false, $start = 0, $limit = 0, $rid = '', $type = false) + { + //查询文件夹所有下级 + $fids = C::t('resources_path')->get_child_fids($fid); + + if ($type) { + $type = $type - 1; + $wheresql = " where (pfid in(%n) and `type` = " . $type . ")"; + } else { + $wheresql = " where (pfid in(%n) and `type` = 0)"; + } + $wheresql = " where (pfid in(%n) and `type` = 0)"; + $params = array($this->_table, $fids); + + if ($rid) { + if ($type) { + $type = $type - 1; + $wheresql .= " or ((rid = %s and `type` = 1) or `type` = 0)"; + } else { + $wheresql .= " or ((rid = %s and `type` = 1) or `type` = 0)"; + } + + $params[] = $rid; + } else { + if ($type) { + $type = $type - 1; + $wheresql .= " or ((rid = %s and `type` = 1) or `type` = 0)"; + } else { + $wheresql .= " or (pfid = %d and `type` = 1 and rid = '')"; + } + $params[] = $fid; + } + if ($counts) { + return DB::result_first("select count(*) from %t $wheresql", $params); + } + $limitsql = $limit ? DB::limit($start, $limit) : ''; + $events = array(); + $uids = array(); + include_once libfile('function/use'); + foreach (DB::fetch_all("select * from %t $wheresql order by dateline desc $limitsql", $params) as $v) { + $v['body_data'] = unserialize($v['body_data']); + $v['body_data']['msg'] = preg_replace_callback("/@\[(.+?):(.+?)\]/i", "atreplacement", $v['body_data']['msg']); + $v['body_data']['msg'] = dzzcode($v['body_data']['msg']); + $at_users = array(); + $v['do_lang'] = lang($v['do']); + $v['details'] = lang($v['event_body'], $v['body_data']); + $v['fdate'] = dgmdate($v['dateline'], 'u'); + $uids[] = $v['uid']; + $events[] = $v; + } + $events = self::result_events_has_avatarstatusinfo($uids, $events); + return $events; + } + + public function result_events_has_avatarstatusinfo($uids, $events) + { + $uids = array_unique($uids); + $avatars = array(); + foreach (DB::fetch_all("select u.avatarstatus,u.uid,s.svalue from %t u left join %t s on u.uid=s.uid and s.skey=%s where u.uid in(%n)", array('user', 'user_setting', 'headerColor', $uids)) as $v) { + if ($v['avatarstatus'] == 1) { + $avatars[$v['uid']]['avatarstatus'] = 1; + } else { + $avatars[$v['uid']]['avatarstatus'] = 0; + $avatars[$v['uid']]['headerColor'] = $v['svalue']; + } + } + $fevents = array(); + foreach ($events as $v) { + $v['avatarstatus'] = $avatars[$v['uid']]['avatarstatus']; + if (!$avatars[$v['uid']]['avatarstatus'] && isset($avatars[$v['uid']]['headerColor'])) { + $v['headerColor'] = $avatars[$v['uid']]['headerColor']; + } + $fevents[] = $v; + } + return $fevents; + } + + //查询该文件最近的动态 + public function fetch_by_ridlast($rid) + { + $event = array(); + $result = DB::fetch_first("select * from %t where rid = %s and `type` = %d", array($this->_table, $rid, 0)); + $body_data = unserialize($result['body_data']); + $body_data['msg'] = dzzcode($body_data['msg']); + $event = array( + 'details' => lang($result['event_body'], $body_data), + 'fdate' => dgmdate($result['dateline'], 'u'), + ); + return $event; + } + + //查询当前用户所有动态 + public function fetch_all_event($start = 0, $limit = 0, $condition = array(), $ordersql = '', $count = false) + { + $limitsql = $limit ? DB::limit($start, $limit) : ''; + $wheresql = ' 1 '; + $uid = getglobal('uid'); + $params = array($this->_table, 'folder'); + $explorer_setting = get_resources_some_setting();//获取系统设置 + $powerarr = perm_binPerm::getPowerArr(); + + //用户条件 + $usercondition = array(); + //如果筛选条件没有用户限制,默认查询当前用户网盘数据 + if (!isset($condition['uidval'])) { + //用户自己的文件 + if ($explorer_setting['useronperm']) {//判断当前用户存储是否开启,如果开启则查询当前用户网盘数据 + $usercondition ['nogid'] = " e.gid=0 and e.uid=%d "; + $params[] = $uid; + } + } else { + $uids = $condition['uidval'][0]; + if (in_array($uid, $uids)) { + if ($explorer_setting['useronperm']) {//判断当前用户存储是否开启,如果开启则查询当前用户网盘数据 + $usercondition ['nogid'] = " e.gid=0 and e.uid=%d "; + $params[] = $uid; + } + } + if (count($uids) > 0) {//群组用户限制 + $usercondition ['hasgid'] = " (e.uid in(%n)) "; + } + } + + if (isset($usercondition['nogid'])) $wheresql .= 'and (' . $usercondition ['nogid'] . ')'; + + + //群组条件后需判断有无用户条件 + $orgcondition = array(); + $orgids = C::t('organization')->fetch_all_orgid();//获取所有有管理权限的部门,并排除已关闭的群组或机构 + //我管理的群组或部门 + if ($orgids['orgids_admin']) { + + $orgcondition[] = " e.gid IN (%n) "; + + $params[] = $orgids['orgids_admin']; + } + //我参与的群组 + if ($orgids['orgids_member']) { + $orgcondition[] = " (e.gid IN(%n) and ((f.perm_inherit & %d) OR (e.uid=%d and f.perm_inherit & %d))) "; + $params[] = $orgids['orgids_member']; + $params[] = $powerarr['read2']; + $params[] = $uid; + $params[] = $powerarr['read1']; + } + if ($orgcondition) {//如果有群组条件 + $or = isset($usercondition ['nogid']) ? 'or' : 'and';//判断是否有网盘数据 + if ($usercondition ['hasgid']) {//如果有网盘数据,则与群组条件组合为或的关系 + $wheresql .= " $or ((" . implode(' OR ', $orgcondition) . ") and " . $usercondition ['hasgid'] . ") "; + $params[] = $uids; + } else { + $wheresql .= " $or (" . implode(' OR ', $orgcondition) . ") "; + } + $wheresql = '(' . $wheresql . ')'; + } else { + if (!isset($usercondition ['nogid'])) { + $wheresql .= ' and 0 '; + } + } + + //解析搜索条件 + if ($condition && is_string($condition)) {//字符串条件语句 + $wheresql .= $condition; + } elseif (is_array($condition)) { + foreach ($condition as $k => $v) { + if (!is_array($v)) { + $connect = 'and'; + $wheresql .= $connect . ' e.' . $k . " = '" . $v . "' "; + } else { + $relative = isset($v[1]) ? $v[1] : '='; + $connect = isset($v[2]) ? $v[2] : 'and'; + if ($relative == 'in') { + $wheresql .= $connect . " e." . $k . " " . $relative . " (" . $v[0] . ") "; + } elseif ($relative == 'nowhere') { + continue; + } elseif ($relative == 'stringsql') { + $wheresql .= $connect . " " . $v[0] . " "; + } elseif ($relative == 'like') { + $wheresql .= $connect . " e." . $k . " like %s "; + $params[] = '%' . $v[0] . '%'; + } else { + $wheresql .= $connect . ' e.' . $k . ' ' . $relative . ' ' . $v[0] . ' '; + } + + } + } + } + if ($count) { + return DB::result_first("select count(*) from %t e left join %t f on e.pfid = f.fid where $wheresql $ordersql", $params); + } + $uids = array(); + $events = array(); + foreach (DB::fetch_all("select e.* from %t e left join %t f on e.pfid = f.fid where $wheresql $ordersql $limitsql", $params) as $v) { + $v['body_data'] = unserialize($v['body_data']); + $v['body_data']['msg'] = dzzcode($v['body_data']['msg']); + $v['do_lang'] = lang($v['do']); + $v['details'] = lang($v['event_body'], $v['body_data']); + $v['fdate'] = dgmdate($v['dateline'], 'u'); + $uids[] = $v['uid']; + $events[] = $v; + } + $events = self::result_events_has_avatarstatusinfo($uids, $events); + return $events; + + } + + //删除评论 + public function delete_comment_by_id($id) + { + $id = intval($id); + $uid = getglobal('uid'); + if (!$comment = parent::fetch($id)) { + return array('error' => lang('comment_not_exists')); + } + //检测删除权限 + $pfid = $comment['pfid']; + if ($folder = C::t('folder')->fetch($pfid)) { + if(($uid != $comment['uid']) && !perm_check::checkperm_Container($folder['fid'], 'delete2') && !($uid == $folder['uid'] && perm_check::checkperm_Container($folder['fid'], 'delete1'))) { + return array('error' => lang('no_privilege')); + } + } + if (parent::delete($id)) { + return array('success' => true); + } else { + return array('error' => lang('delete_error')); + } + + } + + /* + * #group&do=file&gid=1&fid=13 + * #group&gid=1 + * #home&fid=1 + * #home&do=file&fid=11 + * */ + public function get_showtpl_hash_by_gpfid($pfid, $gid = 0) + { + $hash = ''; + //判断是否是群组内操作 + if ($gid > 0) { + $gfid = DB::result_first("select fid from %t where orgid = %d", array('organization', $gid)); + //判断是否是群组跟目录 + if ($pfid == $gfid) { + //$hash=MOD_URL.'#group&gid='.$gid; + $hash = '#group&gid=' . $gid; + } else { + //$hash=MOD_URL.'#group&do=file&gid='.$gid.'&fid='.$pfid; + $hash = '#group&do=file&gid=' . $gid . '&fid=' . $pfid; + } + } else { + $hfid = DB::result_first("select pfid from %t where fid = %d", array('folder', $pfid)); + //判断是否是个人根目录 + if ($hfid == 0) { + //$hash=getglobal('siteurl').MOD_URL.'#home&fid='.$pfid; + $hash = '#home&fid=' . $pfid; + } else { + //$hash=getglobal('siteurl').MOD_URL.'#home&do=file&fid='.$pfid; + $hash = '#home&do=file&fid=' . $pfid; + } + } + return $hash; + } + + public function update_event_by_pfid($pfid, $opfid) + { + DB::update($this->_table, array('pfid' => $opfid), array('pfid' => $opfid)); + } + +} \ No newline at end of file diff --git a/core/class/table/table_resources_path.php b/core/class/table/table_resources_path.php new file mode 100644 index 0000000..77a3073 --- /dev/null +++ b/core/class/table/table_resources_path.php @@ -0,0 +1,247 @@ +_table = 'resources_path'; + $this->_pk = 'fid'; + $this->_pre_cache_key = 'resourcespath_'; + $this->_cache_ttl = 60 * 60; + parent::__construct(); + } + /* + * 返回文件夹路径 + * $pfid=>文件夹id + * $pathkey=>为ture查询pathkey,兼容之前数据(临时处理) + * */ + public function fetch_pathby_pfid($pfid,$pathkey = false){ + $pfid = intval($pfid); + $fileds = ($pathkey) ? 'path,pathkey':'path'; + if($pathkey){ + $cachekey = 'patharr_'.$pfid; + $fileds = 'path,pathkey'; + }else{ + $cachekey = 'path_'.$pfid; + $fileds = 'path'; + } + if($data = $this->fetch_cache($cachekey)){ + return $data; + } + if($data = DB::fetch_first("select {$fileds} from %t where fid = %d",array($this->_table,$pfid))){ + $data = (!$pathkey) ? $data['path']:$data; + $this->store_cache($cachekey,$data); + return $data; + } + return false; + } + public function update_by_fid($fid,$setarr){ + if(DB::update($this->_table,$setarr,array('fid'=>$fid))){ + $cacheky1 = 'patharr_'.$fid; + $cacheky2 = 'path_'.$fid; + $this->clear_cache($cacheky1); + $this->clear_cache($cacheky2); + return true; + } + return false; + } + public function fetch_fid_bypath($path){ + if($data = DB::fetch_first("select p.fid from %t p left join %t f on f.fid = p.fid where p.path = %s and f.isdelete < %d",array($this->_table,'folder',$path,1))){ + return $data['fid']; + } + return false; + } + //获取路径文件名和文件所在文件夹fid + public function get_filename_patharr($path){ + $patharr = array(); + $dir = dirname($path).'/'; + if(!$pfid = C::t('resources_path')->fetch_fid_bypath($dir)){ + return $patharr; + } + $filename = preg_replace('/^.+[\\\\\\/]/', '', $path); + //如果是文件夹 + if(!$filename){ + $patharr = preg_split('/[\\\\\\/]/',$path); + $patharr = array_filter($patharr); + $filename = end($patharr); + } + $patharr['filename'] = $filename; + $patharr['pfid'] = $pfid; + return $patharr; + } + public function delete_by_path($path){ + $path = self::path_transferred_meaning($path); + $fids = array(); + foreach(DB::fetch_all("select fid from %t where path regexp %s",array($this->_table,'^'.$path.'.*')) as $v){ + $fids[] = $v['fid']; + } + + if(self::delete_by_fid($fids)){ + return true; + } + return false; + } + public function delete_by_fid($fid){ + if(!is_array($fid)) $fids = array($fid); + else $fids = $fid; + $cachekey1 = array(); + $cachekey2 = array(); + foreach($fids as $v){ + $cachekey1[] = 'patharr_'.$v; + $cachekey2[] = 'path_'.$v; + } + if(self::delete($fid)){ + $this->clear_cache($cachekey1); + $this->clear_cache($cachekey2); + return true; + } + return false; + } + /*public function delete_by_pathkey($pathkey){ + return DB::delete($this->_table,"pathkey = ".$pathkey); + }*/ + //通过pathkey获取文件夹下级及自身fid + public function fetch_folder_containfid_by_pfid($pfid){ + $pfids = array($pfid); + $path = $this->fetch_pathby_pfid($pfid,true); + $pathkey = $path['pathkey']; + $results = DB::fetch_all("select * from %t where pathkey regexp %s",array($this->_table,'^'.$pathkey.'.+')); + foreach($results as $v){ + $pfids[] = $v['fid']; + } + return $pfids; + } + public function fetch_by_path($path,$prefix=''){ + $opath = trim($path); + $patharr = explode('/',$opath); + $path = self::path_transferred_meaning($path); + $uid = getglobal('uid'); + if($prefix){ + switch ($prefix){ + case 'g': + $orgid = DB::result_first("select orgid from %t where orgname = %s and forgid = %d and `type` = %d",array('organization',$patharr[0],0,1)); + $path = 'dzz:gid_'.$orgid.':'.$path; + $fid = DB::result_first("select fid from %t where path = %s ",array($this->_table,$path)); + break; + case 'o': + $orgid = DB::result_first("select orgid from %t where orgname = %s and forgid = %d and `type` = %d",array('organization',$patharr[0],0,0)); + $path = 'dzz:gid_'.$orgid.':'.$path; + $fid = DB::result_first("select fid from %t where path = %s ",array($this->_table,$path)); + break; + case 'c': + $fid = 'c_'.DB::result_first("select id from %t where uid = %d and catname = %s",array('resources_cat',$uid,$patharr[0])); + break; + } + }else{ + $upath = 'dzz:uid_'.$uid.':'.$opath; + if(!$fid = DB::result_first("select p.fid from %t p left join %t f on p.fid = f.fid where p.path = %s and f.deldateline < 1 ",array($this->_table,'folder',$upath))){ + $fid = DB::result_first("select p.fid from %t p left join %t f on p.fid = f.fid where p.path regexp %s and f.deldateline < 1",array($this->_table,'folder','^dzz:.+:'.$path.'$')); + } + } + return $fid; + } + //修改名称时文件夹路径调整 + public function update_path_by_fid($fid,$name){ + global $_G; + $_G['neworgname'] = $name; + $path = $this->fetch_pathby_pfid($fid); + $paths = substr($path,0,-1);//去掉最后斜杠 + $pathname = preg_replace('/^dzz:.+:/','',$paths);//取出路径部分 + $patharr = explode('/',$pathname);//分割成数组 + $content = end($patharr);//取得目录最后一级名字 + $newpath = preg_replace_callback('/(.+?)'.$content.'$/',function($m){ + return $m[1].getglobal('neworgname').'/'; + },$paths); + if($content != $name) $newpath = str_replace($content,$name,$path); + else return true; + $regpath = self::path_transferred_meaning($path); + $cachkey1 = array(); + $cachkey2 = array(); + foreach(DB::fetch_all("select fid from %t where path regexp %s",array($this->_table,'^'.$regpath.'.*')) as $v){ + $cachkey1[] = 'patharr_'.$v['fid']; + $cachkey2[] = 'path_'.$v['fid']; + } + $sql = "update %t set path = replace(path,%s,%s) where path regexp %s"; + if(DB::query($sql,array($this->_table,$path,$newpath,'^'.$regpath.'.*'))){ + $this->clear_cache($cachkey1); + $this->clear_cache($cachkey2); + return true; + }else{ + return false; + } + } + //修改文件位置时 + public function update_pathdata_by_fid($fid,$ofid,$noself = false){ + if($paths = $this->fetch_pathby_pfid($fid,true)){ + $opaths = $this->fetch_pathby_pfid($ofid,true); + $path = dirname($paths['path']).'/'; + $opath = $opaths['path']; + $pathkey = explode('-',$paths['pathkey']); + array_pop($pathkey); + $pathkey=implode('-',$pathkey); + $opathkey = $opaths['pathkey']; + $sql = "update %t set path = replace(path,%s,%s),pathkey = replace(pathkey,%s,%s) where path regexp %s"; + $paths['path'] = self::path_transferred_meaning($paths['path']); + if($noself) $likepath = $paths['path'].'.+'; + else $likepath = $paths['path'].'.*'; + $cachkey1 = array(); + $cachkey2 = array(); + foreach(DB::fetch_all("select fid from %t where path regexp %s",array($this->_table,'^'.$likepath)) as $v){ + $cachkey1[] = 'patharr_'.$v['fid']; + $cachkey2[] = 'path_'.$v['fid']; + } + if(DB::query($sql,array($this->_table,$path,$opath,$pathkey,$opathkey,'^'.$likepath))){ + $this->clear_cache($cachkey1); + $this->clear_cache($cachkey2); + return true; + }else{ + return false; + } + }else{ + return false; + } + + + } + //转义查询语句当中的path + public function path_transferred_meaning($path){ + return str_replace(array('\'','(',')','+','^','$','{','}','[',']','#'),array("\'",'\(','\)','\+','\^','\$','\{','\}','\[','\]','\#'),$path); + } + //查询当前目录及其下级的fid + public function get_child_fids($fid){ + $path = self::fetch_pathby_pfid($fid,true); + $pathkey = $path['pathkey']; + $fids = array(); + foreach(DB::fetch_all("select fid from %t where pathkey regexp %s",array($this->_table,'^'.$pathkey.'.*')) as $v){ + $fids[] = $v['fid']; + } + return $fids; + } + //获取文件夹的目录信息(路径及所在位置的顶级目录fid,其中路径不包含顶级目录) + public function get_dirinfo_by_fid($fid){ + $result = array(); + $pathkeys = self::fetch_pathby_pfid($fid,true); + $fids = str_replace('_','',$pathkeys['pathkey']); + $fids = explode('-',$fids); + $result['pfid'] = $fids[0]; + $path = preg_replace('/^dzz:(.+?):/','',$pathkeys['path']); + $patharr = explode('/',$path); + unset($patharr[0]); + $result['path'] = implode('/',$patharr); + return $result; + + } + public function parse_path_get_rootdirinfo($path){ + $dirpath = explode('/',$path); + $rootpath = $dirpath[0].'/';//根目录路径 + $rootfid = DB::result_first("select fid from %t where path = %s order by fid DESC",array($this->_table,self::path_transferred_meaning($rootpath))); + if(!$rootfid){ + return false; + } + $path = str_replace($rootpath,'',$path); + return array('path'=>$path,'pfid'=>$rootfid); + } +} \ No newline at end of file diff --git a/core/class/table/table_resources_permgroup.php b/core/class/table/table_resources_permgroup.php new file mode 100644 index 0000000..a6cb2ad --- /dev/null +++ b/core/class/table/table_resources_permgroup.php @@ -0,0 +1,72 @@ +_table = 'resources_permgroup'; + $this->_pk = 'id'; + + parent::__construct(); + } + public function insert($setarr){ + if($setarr['default'] == 1){//删除原有默认值 + if($did = DB::result_first("select `id` from %t where `default` = %d",array($this->_table,1))){ + parent::update($did,array('default'=>0)); + } + } + if($insert = parent::insert($setarr,1)){ + return $insert; + } + return false; + } + public function update_by_id($id,$setarr){ + if($setarr['default'] == 1){//删除原有默认值 + if($did = DB::result_first("select id from %t where `default` = %d",array($this->_table,1))){ + parent::update($did,array('default'=>0)); + } + } + return parent::update($id,$setarr); + } + public function fetch_by_name($pername){ + return DB::result_first("select count(*) from %t where pername = %s",array($this->_table,$pername)); + } + public function fetch_all($off = false){ + $params= array($this->_table); + $wheresql = ''; + if($off){ + $wheresql = "where off != %d"; + $params[] = 1; + } + return DB::fetch_all("select * from %t $wheresql",$params); + } + public function update_off_status($id,$off){ + $id = intval($id); + $off= intval($off); + if(parent::fetch($id)){ + if(parent::update($id,array('off'=>$off))){ + return array('success'=>true); + } + } + return array('error'=>true); + } + public function setdefault_by_id($id){ + $id = intval($id); + if(!$id) return false; + if($did = DB::fetch_first("select id from %t where `default` = %d",array($this->_table,1))){ + parent::update($did,array('default'=>0)); + } + return parent::update($id,array('default'=>1)); + } + public function delete_by_id($id){ + $id = intval($id); + if(!$id) return false; + if(parent::delete($id)){ + return true; + } + return false; + } +} \ No newline at end of file diff --git a/core/class/table/table_resources_recyle.php b/core/class/table/table_resources_recyle.php new file mode 100644 index 0000000..cd3fe66 --- /dev/null +++ b/core/class/table/table_resources_recyle.php @@ -0,0 +1,332 @@ +_table = 'resources_recyle'; + $this->_pk = 'id'; + parent::__construct(); + } + + //插入回收站文件 + public function insert_data($setarr) + { + $arr = array( + 'rid' => $setarr['rid'], + 'uid' => getglobal('uid'), + 'username' => getglobal('username'), + 'gid' => $setarr['gid'], + 'filename' => $setarr['name'], + 'size' => $setarr['size'], + 'pfid' => $setarr['pfid'], + 'deldateline' => $setarr['deldateline'] + ); + $path = C::t('resources_path')->fetch_pathby_pfid($arr['pfid']); + $arr['pathinfo'] = $path; + if ($cid = parent::insert($arr)) { + + if ($path) $path = preg_replace('/dzz:(.+?):/', '', $path); + $hash = C::t('resources_event')->get_showtpl_hash_by_gpfid($setarr['pfid'], $setarr['gid']); + $eventdata = array('username' => $arr['username'], 'filename' => $arr['filename'], 'position' => ($path) ? $path : '', 'hash' => $hash); + if ($setarr['type'] == 'folder') { + + if (C::t('resources_event')->addevent_by_pfid($setarr['pfid'], 'delete_folder', 'delfolder', $eventdata, $setarr['gid'], $setarr['rid'], $setarr['name'])) { + return true; + } else { + parent::delete($cid); + return false; + } + } else { + if (C::t('resources_event')->addevent_by_pfid($setarr['pfid'], 'delete_file', 'delfile', $eventdata, $setarr['gid'], $setarr['rid'], $setarr['name'])) { + return true; + } else { + parent::delete($cid); + return false; + } + } + + } + } + + //查询群组回收站文件 + public function fetch_by_gid($gid) + { + $gid = intval($gid); + $result = array(); + foreach (DB::fetch_all("select * from %t where gid = %d", array($this->_table, $gid)) as $v) { + $v['info'] = C::t('resources')->fetch_by_rid($v['rid']); + $v['info']['deldateline'] = dgmdate($v['info']['deldateline']); + $result[] = $v; + } + return $result; + } + + //查询回收站文件 + public function fetch_by_ids($ids) + { + if (!is_array($ids)) $ids = (array)$ids; + $results = DB::fetch_all("select * from %t where id in(%n)", array($this->_table, $ids)); + return $results; + } + + //查询有权限回收站文件:我删除的和我管理的群组的(其他普通用户删除的文件不列出=>即我有权限删除的) + public function fetch_all_recycle_data() + { + global $_G; + $uid = $_G['uid']; + $recycles = array(); + $orgids = C::t('organization')->fetch_all_orgid(); + $manageorgid = $orgids['orgids_admin']; + if ($results = DB::fetch_all("select * from %t where uid = %d or gid in(%n)", array($this->_table, $uid, $manageorgid))) { + $recycles = $results; + } + return $recycles; + } + + //查询回收站数据 + public function fetch_all_rid($pfids=array()) + { + $rids = array(); + $wheresql = ' where 1 '; + $params = array($this->table); + if($pfids){ + $wheresql.=" and pfid IN (%n)"; + $params[]=$pfids; + } + $uid = getglobal('uid'); + //查询有管理权限的群组id + $manageorg = C::t('organization')->fetch_all_manage_orgid(); + $manageorgid = array(); + foreach ($manageorg as $v) { + $manageorgid[] = $v['orgid']; + } + $wheresql .= 'and uid = %d or gid in(%n)'; + $params[] = $uid; + $params[] = $manageorgid; + foreach (DB::fetch_all("select rid from %t $wheresql ", $params) as $v) { + $rids[] = $v['rid']; + } + return $rids; + } + + //查询回收站文件信息 + public function fetch_all_recycle($start = 0, $limit = 0, $condition = array(), $ordersql = '', $count = false) + { + global $_G; + $limitsql = $limit ? DB::limit($start, $limit) : ''; + $wheresql = ' where 1 '; + $params = array($this->table, 'resources', 'folder'); + //解析搜索条件 + if ($condition && is_string($condition)) {//字符串条件语句 + $wheresql .= $condition; + } elseif (is_array($condition)) { + foreach ($condition as $k => $v) { + if (!is_array($v)) { + $connect = 'and'; + $wheresql .= $connect . ' ' . $k . " = '" . $v . "' "; + } else { + $relative = isset($v[1]) ? $v[1] : '='; + $connect = isset($v[2]) ? $v[2] : 'and'; + if ($relative == 'in') { + $wheresql .= $connect . " " . $k . " " . $relative . " (%n) "; + $params[] = $v[0]; + } elseif ($relative == 'stringsql') { + $wheresql .= $connect . " " . $v[0] . " "; + } elseif ($relative == 'like') { + $wheresql .= $connect . " " . $k . " like %s "; + $params[] = '%' . $v[0] . '%'; + } else { + $wheresql .= $connect . ' ' . $k . ' ' . $relative . ' ' . $v[0] . ' '; + } + + } + } + } + $explorer_setting = get_resources_some_setting(); + $orgids = C::t('organization')->fetch_all_orgid();//获取所有有管理权限的部门 + $powerarr = perm_binPerm::getPowerArr(); + $or = array(); + //如果没有群组和网盘限制条件,默认查询我有权限管理的群组和我删除的文件 + if (!isset($condition['re.gid']) && !isset($condition['re.pfid'])) { + $uid = $_G['uid']; + if ($_G['adminid'] == 1) { + if ($explorer_setting['useronperm']) { + $or[] = '(re.uid = %d and re.gid = 0)'; + $params[] = $uid; + } + $gids = array_unique(array_merge($orgids['orgids_admin'], $orgids['orgids_member'])); + $or[] = ' (re.gid in (%n) )'; + $params[] = $gids; + + } else { + if ($explorer_setting['useronperm']) { + $or[] = '(re.uid = %d and re.gid = 0)'; + $params[] = $uid; + } + + //我管理的群组或部门的文件 + if ($orgids['orgids_admin']) { + $or[] = "r.gid IN (%n)"; + $params[] = $orgids['orgids_admin']; + } + //我参与的群组的文件 + if ($orgids['orgids_member']) { + $or[] = "(re.gid IN(%n) and ((f.perm_inherit & %d) OR (re.uid=%d and f.perm_inherit & %d)))"; + $params[] = $orgids['orgids_member']; + $params[] = $powerarr['delete2']; + $params[] = $_G['uid']; + $params[] = $powerarr['delete1']; + } + + } + } else { + if ($_G['adminid'] != 1 && !in_array($_G['uid'], $orgids['orgids_admin'])) { + $wheresql .= " and ((f.perm_inherit & %d) OR (re.uid=%d and f.perm_inherit & %d))"; + $params[] = $powerarr['delete2']; + $params[] = $_G['uid']; + $params[] = $powerarr['delete1']; + } + } + if ($or) $wheresql .= " and (" . implode(' OR ', $or) . ")"; + if ($count) { + return DB::result_first("select count(*) from %t re left join %t r on re.rid=r.rid left join %t f on re.pfid=f.fid $wheresql $ordersql $limitsql ", $params); + } + $selectfileds = "re.id,re.deldateline,re.username,re.filename,re.pathinfo,r.name,r.size,r.rid,re.pfid,r.type,r.pfid,r.oid,r.gid"; + foreach (DB::fetch_all("select $selectfileds from %t re + left join %t r on re.rid=r.rid + left join %t f on re.pfid=f.fid + $wheresql $ordersql $limitsql ", $params) as $v) { + if ($v['pathinfo']) { + $path = preg_replace('/dzz:(.+?):/', '', $v['pathinfo']); + $v['from'] = substr($path, 0, -1); + } + //计算最终删除时间 + $v['dpath'] = dzzencode($v['rid']); + if ($explorer_setting['finallydelete'] > 0) { + $endtime = intval($explorer_setting['finallydelete']); + $dateend = strtotime("+" . $endtime . "day", $v['deldateline']); + $v['finallydate'] = self::diffBetweenTwoDays($dateend); + } else { + $v['finallydate'] = '--'; + } + $v['deldateline'] = dgmdate($v['deldateline'], 'Y-m-d'); + //获取文件图标 + $v['img'] = C::t('resources')->get_icosinfo_by_rid($v['rid']); + //文件大小信息 + $v['fsize'] = ($v['size']) ? formatsize($v['size']) : 0; + $v['isdelete'] = 1; + $result[$v['rid']] = $v; + } + return $result; + } + + //获取最终删除时间 + public function diffBetweenTwoDays($end) + { + $days = 0; + $start = TIMESTAMP; + if ($start < $end) { + $days = floor(($start - $end) / 86400); + } + if ($days < 0) $days = 0; + return $days; + } + + //文件恢复 + public function recover_file_by_id($ids) + { + global $_G; + $uid = $_G['uid']; + if (!is_array($ids)) $ids = (array)$ids; + $idarr = array(); + foreach ($ids as $id) { + if (!$recyle = parent::fetch($id)) { + continue; + } + $rid = $recyle['rid']; + if (!$result = DB::fetch_first("select * from %t where rid = %s", array('resources', $rid))) { + continue; + } + if ($result['gid'] > 0) { + $pfid = $result['pfid']; + $perm = perm_check::getPerm($result['pfid']); + if ($perm > 0) { + if (!perm_binPerm::havePower('delete2', $perm) && !(perm_binPerm::havePower('delete1', $perm) && $result['uid'] == $uid)) { + continue; + } + } + } + if (DB::update('resources', array('isdelete' => 0, 'deldateline' => 0), array('rid' => $rid)) && parent::delete($id)) { + $hash = C::t('resources_event')->get_showtpl_hash_by_gpfid($result['pfid'], $result['gid']); + $eventdata = array( + 'username' => getglobal('username'), + 'filename' => $result['name'], + 'hash' => $hash + ); + if (C::t('resources_event')->addevent_by_pfid($result['pfid'], 'recover_file', 'recover', $eventdata, $result['gid'], $rid, $result['name'])) { + $idarr[] = $id; + } else { + DB::update($this->_table, array('isdelete' => 1, 'deldateline' => $result['deldateline']), array('rid' => $rid)); + continue; + } + + } + + } + return $idarr; + } + + public function fetch_by_rid($rid) + { + return DB::fetch_first("select * from %t where rid=%s", array($this->_table, $rid)); + } + + public function delete_by_rid($rid) + { + if (!is_array($rid)) $rid = (array)$rid; + $rids = ''; + foreach ($rid as $v) { + $rids .= "'" . $v . "',"; + } + $rids = substr($rids, 0, -1); + DB::delete($this->_table, "rid in (" . $rids . ")"); + return true; + } + + //彻底删除 + public function delete_by_id($id) + { + if (!is_array($id)) $id = (array)$id; + $ids = array(); + foreach ($id as $v) { + if (!$recyle = parent::fetch($v)) { + continue; + } + if (C::t('resources')->delete_by_rid($recyle['rid'])) { + $ids[] = $v; + } + } + return $ids; + } + + //根据rid获取回收站数据 + public function get_data_by_rid($rid) + { + $rid = trim($rid); + return DB::fetch_first("select * from %t where rid = %s", array($this->_table, $rid)); + } + + public function fetch_rid_bydate($date) + { + $rids = array(); + foreach (DB::fetch_all("select rid from %t where deldateline <= %s", array($this->_table, $date)) as $v) { + $rids[] = $v['rid']; + } + return $rids; + } +} \ No newline at end of file diff --git a/core/class/table/table_resources_statis.php b/core/class/table/table_resources_statis.php new file mode 100644 index 0000000..a417950 --- /dev/null +++ b/core/class/table/table_resources_statis.php @@ -0,0 +1,149 @@ +_table = 'resources_statis'; + $this->_pk = 'rid'; + parent::__construct(); + } + //根据fid增加统计数据 + public function add_statis_by_fid($fid,$setarr){ + global $_G; + $uid = $_G['uid']; + $fid = intval($fid); + if(!DB::result_first("select count(*) from %t where fid = %d",array($this->_table,$fid))){ + $fileinfo = C::t('folder')->fetch($fid); + $insertarr = array('editdateline'=>$fileinfo['dateline'],'pfid'=>$fileinfo['pfid'],'uid'=>$uid,'opendateline'=>$fileinfo['dateline'],'fid'=>$fid); + if(!$insert = parent::insert($insertarr,1)){ + return false; + } + } + $params = array($this->_table); + $editsql = ''; + $editarr = array(); + //对有数据的进行修改 + foreach($setarr as $k=>$v){ + $increasearr = array('edits','views','downs'); + $editarr = array('uid','editdateline','opendateline','fid'); + if(in_array($k,$increasearr)){ + $editsql .= $k.'='.$k.'+'.$v.','; + }elseif(in_array($k,$editarr)){ + $editsql .= $k.'=%d'.','; + $params[] = $v; + } + } + $editsql = substr($editsql,0,-1); + $params[] = $fid; + if($ret = DB::query("update %t set $editsql where fid = %d",$params)){ + return true; + } + return true; + } + //根据rid增加统计数据 + public function add_statis_by_rid($rids,$setarr){//增加统计数据 + global $_G; + $uid = $_G['uid']; + if(!is_array($rids)) $rids = (array)$rids; + + $statis = array(); + $statisrid = array(); + //查询rid数组,判断当前$rids数组是否在数据库已经有数据 + $statisrids = DB::fetch_all("select rid from %t where rid in(%n)",array($this->_table,$rids)); + foreach($statisrids as $v){ + $statisrid[] = $v['rid']; + } + foreach($rids as $v){ + if(!in_array($v,$statisrid)){ + $statis[] = $v; + } + } + //无数据的进行创建 + if($statis){ + foreach($statis as $v){ + $fileinfo = C::t('resources')->fetch_info_by_rid($v); + $insertarr = array('rid'=>$v,'editdateline'=>$fileinfo['dateline'],'pfid'=>$fileinfo['pfid'],'uid'=>$uid,'opendateline'=>$fileinfo['dateline']); + if($fileinfo['oid'] && $fileinfo['type'] == 'folder') $insertarr['oid']; + if(!parent::insert($insertarr,1)){ + $index = array_search($v,$rids); + unset($rids[$index]); + } + } + } + + $params = array($this->_table); + $editsql = ''; + //对有数据的进行修改 + foreach($setarr as $k=>$v){ + $increasearr = array('edits','views','downs'); + $editarr = array('uid','editdateline','opendateline','fid'); + if(in_array($k,$increasearr)){ + $editsql .= $k.'='.$k.'+'.$v.','; + }elseif(in_array($k,$editarr)){ + $editsql .= $k.'=%d'.','; + $params[] = $v; + } + } + $editsql = substr($editsql,0,-1); + $wheresql = ' where rid in (%n)'; + $params[] = $rids; + if(DB::query("update %t set $editsql $wheresql",$params)){ + return true; + } + return true; + } + public function delete_by_rid($rid){ + if(!is_array($rid)) $rid = (array)$rid; + return DB::delete($this->_table,'rid in('.dimplode($rid).')'); + } + + public function fetch_by_fid($fid){ + $fid = intval($fid); + return DB::fetch_first("select * from %t where fid = %d",array($this->_table,$fid)); + } + public function fetch_by_rid($rid){ + $rid = trim($rid); + return DB::fetch_first("select * from %t where rid = %s",array($this->_table,$rid)); + } + //最近使用文件夹 + public function fetch_folder_by_uid($limit = 5){ + global $_G; + $uid = getglobal('uid');; + $folderdata = array(); + $orderby = ' order by edits desc,views desc,editdateline desc,opendateline desc'; + $limitsql = ' limit '.$limit; + $folders = DB::fetch_all("select * from %t where uid = %d and fid != 0 and rid != '' $orderby $limitsql",array($this->_table,$uid)); + return $folders; + } + + //最近使用的文件 + public function fetch_files_by_uid($limit = 20){ + global $_G; + $uid = getglobal('uid'); + $data = array(); + $param = array($this->_table,$uid); + $wheresql = " where uid = %d and fid = 0 and rid != '' "; + + $orderby = ' order by edits desc,views desc,editdateline desc,opendateline desc'; + $limitsql = ' limit '.$limit; + $files = DB::fetch_all("select * from %t $wheresql $orderby $limitsql",$param); + return $files; + + } + public function fetch_recent_files_by_uid($limit =100){ + $files = self::fetch_files_by_uid(); + $folders = self::fetch_folder_by_uid(); + $results = array(); + foreach($folders as $v){ + $results[] = $v; + } + foreach($files as $v){ + $results[] = $v; + } + return $results; + } +} \ No newline at end of file diff --git a/core/class/table/table_resources_tag.php b/core/class/table/table_resources_tag.php new file mode 100644 index 0000000..16ad999 --- /dev/null +++ b/core/class/table/table_resources_tag.php @@ -0,0 +1,180 @@ +_table = 'resources_tag'; + parent::__construct(); + } + + public function delete_by_rid($rid, $tid = '',$event=1) + { + + global $_G; + + + $tids = array(); + $deltagnames=array(); + if ($tid) { + // return DB::delete($this->_table, 'rid in(' . dimplode($rid) . ') and tid = ' . $tid); + $tids=array($tid); + } else { + foreach (DB::fetch_all("select tid from %t where rid = %s", array($this->_table, $rid)) as $v) { + $tids[] = $v['tid']; + } + } + if($tids){ + foreach(C::t('tag')->fetch_all($tids) as $tag){ + $deltagnames[]=$tag['tagname']; + } + } + if($ret=DB::delete($this->_table, "rid ='{$rid}' and tid IN(".dimplode($tids).")")){ + //减少使用数 + C::t('tag')->addhot_by_tid($tids, -1); + if($event){ + //添加动态 + $uid = $_G['uid']; + $username = $_G['username']; + //查询文件信息 + if (!$fileinfo = DB::fetch_first("select * from %t where rid = %s", array('resources', $rid))) { + return false; + } else { + $path = C::t('resources_path')->fetch_pathby_pfid($fileinfo['pfid']); + $path = preg_replace('/dzz:(.+?):/', '', $path . $fileinfo['name']); + } + $eventdata = array('username' => $username, 'filename' => $fileinfo['name'], 'tagname' => implode(',', $deltagnames), 'position' => $path); + C::t('resources_event')->addevent_by_pfid($fileinfo['pfid'], 'del_tags', 'deltag', $eventdata, $fileinfo['gid'], $rid, $fileinfo['name']); + } + } + return true; + } + + + public function insert_data($rid, $tagnames,$isall=1,$idtype='explorer') + { + global $_G; + $uid = $_G['uid']; + $username = $_G['username']; + //查询文件信息 + if (!$fileinfo = DB::fetch_first("select * from %t where rid = %s", array('resources', $rid))) { + return false; + } else { + $path = C::t('resources_path')->fetch_pathby_pfid($fileinfo['pfid']); + $path = preg_replace('/dzz:(.+?):/', '', $path . $fileinfo['name']); + } + //获取文件原有标签数据 + $return = DB::fetch_all("select rt.tid,t.tagname from %t rt left join %t t on rt.tid = t.tid where rt.rid = %s", array($this->_table, 'tag', $rid)); + + $addtags = $deleted = $deltids = $nochangetids = $deltags = array(); + //获取标签数据 + $tags = C::t('tag')->insert_data($tagnames, $idtype); + $tids = array(); + foreach ($tags as $v) { + $tids[] = $v['tid']; + } + foreach ($return as $v) { + if (!in_array($v['tid'], $tids)) { + $deltids[] = $v['tid']; + $deleted[] = array('tid' => $v['tid'], 'tagname' => $v['tagname']); + $deltagnames[] = $v['tagname']; + } else { + $nochangetids[] = $v['tid']; + } + } + //需要移除的标签 + if ($isall && count($deltids)) { + //移除文件标签 + DB::query("delete from %t where rid = %s and tid in(%n)", array($this->_table, $rid, $deltids)); + //减少使用数 + C::t('tag')->addhot_by_tid($deltids, -1); + //添加动态 + $eventdata = array('username' => $username, 'filename' => $fileinfo['name'], 'tagname' => implode(',', $deltagnames), 'position' => $path); + C::t('resources_event')->addevent_by_pfid($fileinfo['pfid'], 'del_tags', 'deltag', $eventdata, $fileinfo['gid'], $rid, $fileinfo['name']); + } + //获取需要添加的标签 + $addtids = (count($nochangetids) > 0) ? array_diff($tids, $nochangetids) : $tids; + if (count($addtids)) { + $addtagnames = array(); + $insertsql = "insert into " . DB::table('resources_tag') . " (rid,tid,uid,username) values "; + foreach ($addtids as $v) { + $insertsql .= "(%s,%d,%d,%s),"; + $params[] = $rid; + $params[] = $v; + $params[] = $uid; + $params[] = $username; + $addtagnames[] = $tags[$v]['tagname']; + $addtags[] = array('tid' => $v, 'tagname' => $tags[$v]['tagname']); + } + $insertsql = substr($insertsql, 0, -1); + //添加文件标签 + DB::query($insertsql, $params); + //增加标签使用数 + C::t('tag')->addhot_by_tid($addtids, 1); + + $addtagnames = implode(',', $addtagnames); + $hash = C::t('resources_event')->get_showtpl_hash_by_gpfid($fileinfo['pfid'], $fileinfo['gid']); + $eventdata = array('username' => $username, 'filename' => $fileinfo['name'], 'tagname' => $addtagnames, 'position' => $path, 'hash' => $hash); + C::t('resources_event')->addevent_by_pfid($fileinfo['pfid'], 'add_tags', 'addtag', $eventdata, $fileinfo['gid'], $rid, $fileinfo['name']); + } + return array('success' => true, 'add' => $addtags, 'del' => $deleted); + } + + public function fetch_tag_by_rid($rid) + { + $rid = trim($rid); + $result = array(); + if ($result = DB::fetch_all("select rt.tid,t.tagname from %t rt left join %t t on rt.tid = t.tid where rt.rid = %s and t.idtype = %s", array($this->_table, 'tag', $rid, 'explorer'))) { + return $result; + } + return $result; + } + + public function fetch_rid_in_tid($tids) + { + if (!is_array($tids)) $tids = (array)$tids; + $rids = array(); + foreach (DB::fetch_all("select rid from %t where tid in(%n)", array($this->_table, $tids)) as $v) { + $rids[] = $v['rid']; + } + return $rids; + } + + public function fetch_rid_by_tid($tids) + { + if (!is_array($tids)) $tids = (array)$tids; + $arr = array(); + //获取标签对应的所有rid + if ($rids = DB::fetch_all("select rid,tid from %t where tid in(%n)", array($this->_table, $tids))) { + //遍历rid数组组成tid为键的数组 + $ridarr = array(); + foreach ($rids as $v) { + $ridarr[$v['tid']][] = $v['rid']; + } + //如果rid数组和tid数组数量一致,即有符合条件rid(含有所有标签的rid) + if (count($ridarr) == count($tids)) { + $i = 0; + //遍历rid数组取交集,得到最后结果 + foreach ($ridarr as $k => $val) { + if ($i == 0) { + $arr = $val; + } else { + $arr = array_intersect($arr, $val); + } + $i++; + } + return $arr; + } else { + return $arr; + } + } else { + return $arr; + + } + } + +} \ No newline at end of file diff --git a/core/class/table/table_resources_version.php b/core/class/table/table_resources_version.php new file mode 100644 index 0000000..7a6d46d --- /dev/null +++ b/core/class/table/table_resources_version.php @@ -0,0 +1,466 @@ +_table = 'resources_version'; + $this->_pk = 'vid'; + $this->_pre_cache_key = 'resources_version_'; + $this->_cache_ttl = 5 * 60; + parent::__construct(); + } + //获取文件图标 + public function getfileimg($data){ + if($data['type']=='image'){ + $data['img']=DZZSCRIPT.'?mod=io&op=thumbnail&size=small&path='.dzzencode('attach::'.$data['aid']); + }elseif($data['type']=='attach' || $data['type']=='document'){ + $data['img']=geticonfromext($data['ext'],$data['type']); + }elseif($data['type']=='dzzdoc'){ + $data['img']=isset($data['img'])?$data['img']:geticonfromext($data['ext'],$data['type']); + }else{ + $data['img']=isset($data['img'])?$data['img']:geticonfromext($data['ext'],$data['type']); + } + return $data['img']; + } + public function fetch_all_by_rid($rid,$limit = '',$count = false){ + $rid = trim($rid); + $versions = array(); + $resources = C::t('resources')->fetch_info_by_rid($rid); + $limitsql = ''; + if($limit){ + $limitarr = explode('-',$limit); + if(count($limitarr) > 1){ + $limitsql = "limit $limitarr[0],$limitarr[1]"; + }else{ + $limitsql = "limit 0,$limitarr[0]"; + } + }/*else{ + $cachekey = 'resourcesversiondata_'.$rid; + if($versions = $this->fetch_cache($cachekey)){ + return $versions; + } + }*/ + if($count){ + return DB::result_first("select count(*) from %t where rid = %s",array($this->_table,$rid)); + } + if($resources['vid'] == 0){ + $attrdata = C::t('resources_attr')->fetch_by_rid($rid,0); + $filedata = array( + 'vid' =>0, + 'rid'=>$rid, + 'uid'=>$resources['uid'], + 'username'=>$resources['username'], + 'vname'=>'', + 'aid'=>$attrdata['aid'], + 'type'=>$resources['type'], + 'ext'=>$resources['ext'], + 'size'=>$resources['size'], + 'dateline'=>$resources['dateline'], + 'img'=>$attrdata['img'] + ); + $filedata['img'] = self::getfileimg($filedata); + $versions[$filedata['vid']] = $filedata; + }else{ + foreach(DB::fetch_all("select * from %t where rid = %s order by dateline desc $limitsql ",array($this->_table,$rid)) as $val){ + $attrdata = C::t('resources_attr')->fetch_by_rid($rid,$val['vid']); + $val['img'] = isset($attrdata['img']) ?$attrdata['img']:''; + $filedata = $val; + $filedata['img'] = self::getfileimg($filedata); + $versions[$val['vid']] = $filedata; + } + } + //$this->store_cache($cachekey,$versions); + return $versions; + } + public function delete_by_vid($vid,$rid=''){ + $vid = intval($vid); + if(!$vinfo = parent::fetch($vid)) return false; + if(empty($rid)) $rid=$vinfo['rid']; + $datainfo = C::t('resources')->fetch_info_by_rid($rid); + if($datainfo['vid']==$vinfo['vid']){//如果删除的是主版本,判断是否是最后一个版本,最后一个版本不让删除 + if(!$nvid=DB::result_first("select vid form %t where rid=%s and vid!=%d order by vid DESC",array($this->_table,$rid,$vid))){ + return false; + } + } + $cachekey = 'resourcesversiondata_'.$rid; + if(parent::delete($vid)){ + if($vinfo['aid']) C::t('attachment')->delete_by_aid($vinfo['aid']); + SpaceSize(-$vinfo['size'],$datainfo['gid'],1,$datainfo['uid']); + C::t('resources_attr')->delete_by_rvid($rid,$vid); + $this->clear_cache($cachekey); + if($nvid){//如果删除的是主版本,需要重新设置文件其他版本为主版本 + self::set_primary_version_by_vid($nvid,true); + } + } + return true; + } + /* public function delete_by_version($icoid,$vid){ + global $_G ; + $cachekey = 'resourcesversiondata_'.$icoid; + if(parent::delete($vid)){ + C::t('resources_attr')->delete_by_rvid($icoid,$vid); + //DB::delete('resources_attr',array('rid'=>$icoid,'vid'=>$vid)); + $eventdata = array( + 'rid'=>$icoid, + 'uid'=>$_G['uid'], + 'username'=>$_G['username'], + 'event_body'=>'delete_version', + 'body_data'=>serialize(array('version'=>$vid)), + 'dateline'=>TIMESTAMP, + ); + DB::insert('resources_event',$eventdata); + $v = DB::result_first("select vid from %t where rid=%s order by dateline DESC ",array($this->_table,$icoid)); + C::t('resources')->update($icoid,array('vid',$v)); + return array('msg'=>$v); + }else return array('error'=>lang('error_delete_version_failed')); + }*/ + public function delete_by_rid($rid){ + $vids=array(); + $aids=array(); + $size=0; + $datainfo = C::t('resources')->fetch($rid); + foreach(DB::fetch_all("select * from %t where rid = %s",array($this->_table,$rid)) as $value){ + $vids[]=$value['vid']; + $aids[]=$value['aid']; + $size+=intval($value['size']); + } + $cachekey = 'resourcesversiondata_'.$rid; + if($ret=parent::delete($vids)){ + $this->clear_cache($cachekey); + foreach($aids as $aid){ + C::t('attachment')->delete_by_aid($aid); + } + SpaceSize(-$size,$datainfo['gid'],1,$datainfo['uid']); + } + return $ret; + } + //上传新版本 + public function add_new_version_by_rid($rid,$setarr,$force=false){ + global $_G,$documentexts; + $cachekey = 'resourcesversiondata_'.$rid; + if(!$resources = C::t('resources')->fetch_info_by_rid($rid)){ + return array('error'=>lang('file_not_exist')); + } + //检测权限 + if (!$force && !perm_check::checkperm_Container($resources['pfid'], 'edit2') && !( $_G['uid'] == $resources['uid'] && perm_check::checkperm_Container($resources['pfid'], 'edit1'))) { + return array('error'=>lang('no_privilege')); + } + //文件类型获取 + $imgexts = array('jpg', 'jpeg', 'gif', 'png', 'bmp'); + if (in_array(strtolower($setarr['ext']), $imgexts)){ + $setarr['type'] = 'image'; + }elseif(in_array(strtoupper($setarr['ext']), $documentexts)){ + $setarr['type'] = 'document'; + }else{ + $setarr['type'] = 'attach'; + } + + //没有版本时,属性表和版本数据处理 + if($resources['vid'] == 0){ + $oldattr = C::t('resources_attr')->fetch_by_rid($rid); + $setarr1 = array( + 'rid'=>$rid, + 'uid'=>$resources['uid'], + 'username'=>$resources['username'], + 'vname'=>'', + 'size'=>$resources['size'], + 'ext'=>$resources['ext'], + 'type'=>$resources['type'], + 'dateline'=>$resources['dateline'], + 'aid'=>intval($oldattr['aid']) + ); + //将原数据插入版本表 + if($oldvid = parent::insert($setarr1,1)){ + C::t('resources_attr')->update_vid_by_rvid($rid,0,$oldvid); + }else{ + return array('error'=>lang('failure')); + } + } + + //文件名 + $filename = $setarr['name']; + $filename = self::getFileName($setarr['name'],$resources['pfid'],$rid); + unset($setarr['name']); + $setarr['rid'] = $rid; + + //新数据插入版本表 + if($vid = parent::insert($setarr,1)){ + $this->clear_cache($cachekey); + //更新主表数据 + //DB::update('resources',array('vid'=>$vid,'size'=>$setarr['size'],'ext'=>$setarr['ext'],'type'=>$setarr['type'],'name'=>$filename),array('rid'=>$rid)) + if(C::t('resources')->update_by_rid($rid,array('vid'=>$vid,'size'=>$setarr['size'],'ext'=>$setarr['ext'],'type'=>$setarr['type'],'name'=>$filename))){ + SpaceSize($setarr['size'],$resources['gid'],true); + //插入属性表数据 + $sourceattrdata = array( + 'postip' => $_G['clientip'], + 'title' => $filename, + 'aid' => isset($setarr['aid']) ? $setarr['aid'] : '', + 'img'=>geticonfromext($setarr['ext'],$setarr['type']) + ); + //插入属性表 + if (C::t('resources_attr')->insert_attr($rid,$vid,$sourceattrdata)) { + if ($setarr['aid']) { + $attach = C::t('attachment')->fetch($setarr['aid']); + C::t('attachment')->update($setarr['aid'], array('copys' => $attach['copys'] + 1));//增加使用数 + } + } + //记录事件 + $path = C::t('resources_path')->fetch_pathby_pfid($resources['pfid']); + $path = preg_replace('/dzz:(.+?):/','',$path); + $event = 'update_version'; + $eventdata = array( + 'title' => $resources['name'], + 'aid' => $setarr['aid'], + 'username' => $setarr['username'], + 'uid' => $setarr['uid'], + 'position'=>$path + ); + C::t('resources_event')->addevent_by_pfid($resources['pfid'], $event, 'updatevesion', $eventdata, $resources['gid'], $rid, $resources['name']); + //增加统计数据 + $statis = array( + 'edits'=>1, + 'uid'=>$_G['uid'], + 'editdateline'=>TIMESTAMP + ); + c::t('resources_statis')->add_statis_by_rid($rid,$statis); + $setarr['fdateline'] = dgmdate($setarr['dateline'],'Y-m-d H:i:s'); + $setarr['vid'] = $vid; + $setarr['size'] = formatsize($setarr['size']); + if($resources['vid'] == 0){ + $setarr['olddatavid'] = $oldvid; + } + $indexarr = array('rid'=>$rid); + Hook::listen('createafter_addindex',$indexarr); + $setarr['dpath'] = dzzencode($rid); + return $setarr; + }else{ + parent::delete($vid); + return array('error'=>lang('failure')); + } + } + + } + //设置主版本 + public function set_primary_version_by_vid($vid){ + global $_G; + if(!$versioninfo = parent::fetch($vid)){ + return array('error'=>lang('file_not_exist')); + } + if(!$fileinfo = C::t('resources')->fetch($versioninfo['rid'])) return array('error'=>lang('file_not_exist')); + + //判断编辑权限 + if (!perm_check::checkperm_Container($fileinfo['pfid'], 'edit2') && !($_G['uid'] == $fileinfo['uid'] && perm_check::checkperm_Container($fileinfo['pfid'], 'edit1'))) { + return array('error'=>lang('no_privilege')); + } + + $vfilename = DB::result_first("select sval from %t where vid = %d and rid = %s and skey = %s",array('resources_attr',$vid,$versioninfo['rid'],'title')); + + //获取不重复的名字 + $filename = self::getFileName($vfilename,$fileinfo['pfid'],$versioninfo['rid']); + if(!$filename){ + $filename = $versioninfo['vname']; + if($filename != $vfilename){ + C::t('resources_attr')->update_by_skey($fileinfo['rid'],$vid,array('title'=>$filename)); + } + } + //更改resources表数据 + $updatearr = array('vid'=>$vid,'name'=>$filename,'size'=>$versioninfo['size'],'ext'=>$versioninfo['ext'],'type'=>$versioninfo['type']); + //DB::update('resources',$updatearr,array('rid'=>$versioninfo['rid'])) + if(C::t('resources')->update_by_rid($versioninfo['rid'],$updatearr)){ + //文件路径信息 + $path = C::t('resources_path')->fetch_pathby_pfid($fileinfo['pfid']); + $path = preg_replace('/dzz:(.+?):/','',$path); + $event = 'setprimary_version'; + $hash = C::t('resources_event')->get_showtpl_hash_by_gpfid($fileinfo['pfid'],$fileinfo['gid']); + $eventdata = array( + 'name' => $filename, + 'oldname'=>$fileinfo['name'], + 'aid' => $versioninfo['aid'], + 'username' => $_G['username'], + 'uid' => $_G['uid'], + 'position'=>$path, + 'hash'=>$hash + ); + $statis = array( + 'edits'=>1, + 'uid'=>$_G['uid'], + 'editdateline'=>TIMESTAMP + ); + C::t('resources_statis')->add_statis_by_rid($versioninfo['rid'],$statis); + C::t('resources_event')->addevent_by_pfid($fileinfo['pfid'], $event, 'setprimaryversion', $eventdata, $fileinfo['gid'], $fileinfo['rid'], $fileinfo['name']); + $indexarr = array('rid'=>$versioninfo['rid']); + Hook::listen('createafter_addindex',$indexarr); + return array('rid'=>$versioninfo['rid']); + }else{ + return array('error'=>lang('explorer_do_failed')); + } + + } + //判断文件重名 + public function getFileName($name,$pfid,$rid = ''){ + static $i=0; + $params = array('resources',$name,$pfid); + $wheresql = ''; + if($rid){ + $wheresql .= " and rid != %s "; + $params[] = $rid; + } + $name=self::name_filter($name); + if(DB::result_first("select COUNT(*) from %t where type!='folder' and name=%s and isdelete<1 and pfid=%d $wheresql",$params)){ + $ext=''; + $namearr=explode('.',$name); + if(count($namearr)>1){ + $ext=$namearr[count($namearr)-1]; + unset($namearr[count($namearr)-1]); + $ext=$ext?('.'.$ext):''; + } + $tname=implode('.',$namearr); + $name=preg_replace("/\(\d+\)/i",'',$tname).'('.($i+1).')'.$ext; + $i+=1; + return self::getFileName($name,$pfid,$rid); + }else{ + return $name; + } + } + //过滤文件名称 + public function name_filter($name){ + return str_replace(array('/','\\',':','*','?','<','>','|','"',"\n"),'',$name); + } + + //根据版本id修改版本名称 + public function update_versionname_by_vid($vid,$vname){ + global $_G; + if(!$versioninfo = parent::fetch($vid)){ + return array('error'=>lang('file_not_exist')); + } + $cachekey = 'resourcesversiondata_'.$versioninfo['rid']; + if(DB::result_first("select count(*) from %t where vname = %s and rid = %s",array($this->_table,$vname,$versioninfo['rid'])) > 0 ){ + return array('error'=>lang('explorer_name_repeat')); + } + //文件基本信息 + $fileinfo = C::t('resources')->fetch_info_by_rid($versioninfo['rid']); + + //判断编辑权限 + if (!perm_check::checkperm_Container($fileinfo['pfid'], 'edit2') && !($_G['uid'] == $fileinfo['uid'] && perm_check::checkperm_Container($fileinfo['pfid'], 'edit1'))) { + return array('error'=>lang('no_privilege')); + } + $sertarr = array('vname'=>$vname,'dateline'=>TIMESTAMP); + if(parent::update($vid,$sertarr)){ + $path = C::t('resources_path')->fetch_pathby_pfid($fileinfo['pfid']); + $path = preg_replace('/dzz:(.+?):/','',$path); + $event = 'edit_versionname'; + $hash = C::t('resources_event')->get_showtpl_hash_by_gpfid($fileinfo['pfid'],$fileinfo['gid']); + $eventdata = array( + 'name' => $vname, + 'filename'=>$fileinfo['name'], + 'username' => $_G['username'], + 'oldvname'=>($versioninfo['name']) ? $versioninfo['name']:dgmdate($versioninfo['dateline'],'Y-m-d H:i:s'), + 'uid' => $_G['uid'], + 'position'=>$path, + 'hash'=>$hash + ); + $statis = array( + 'edits'=>1, + 'uid'=>$_G['uid'], + 'editdateline'=>TIMESTAMP + ); + C::t('resources_statis')->add_statis_by_rid($versioninfo['rid'],$statis); + C::t('resources_event')->addevent_by_pfid($fileinfo['pfid'], $event, 'editversionname', $eventdata, $fileinfo['gid'], $fileinfo['rid'], $fileinfo['name']); + $this->clear_cache($cachekey); + $this->clear_cache($versioninfo['rid']); + return array('vid'=>$vid,'primaryvid'=>$fileinfo['vid'],'fdateline'=>dgmdate($versioninfo['dateline'],'Y-m-d H:i:s')); + }else{ + return array('error'=>lang('explorer_do_failed')); + } + } + + //根据rid修改版本名称,因版本表无数据,需先将主表数据放入版本表,然后更新主表和属性表 + public function update_versionname_by_rid($rid,$vname){ + global $_G; + if(!$fileinfo = C::t('resources')->fetch_info_by_rid($rid)){ + return array('error'=>lang('file_not_exist')); + } + + //判断编辑权限 + if (!perm_check::checkperm_Container($fileinfo['pfid'], 'edit2') && !($_G['uid'] == $fileinfo['uid'] && perm_check::checkperm_Container($fileinfo['pfid'], 'edit1'))) { + return array('error'=>lang('no_privilege')); + } + //没有版本时,属性表和版本数据处理 + $setarr = array( + 'rid'=>$rid, + 'uid'=>$fileinfo['uid'], + 'username'=>$fileinfo['username'], + 'vname'=>$vname, + 'size'=>$fileinfo['size'], + 'ext'=>$fileinfo['ext'], + 'type'=>$fileinfo['type'], + 'dateline'=>TIMESTAMP + ); + //将数据插入版本表 + if($vid = parent::insert($setarr,1)){ + //更新属性表数据 + //DB::update('resources_attr',array('vid'=>$vid),array('rid'=>$rid,'vid'=>0)); + C::t('resources_attr')->update_by_skey($rid,0,array('vid'=>$vid)); + //更新主表数据 + //DB::update('resources',array('vid'=>$vid),array('rid'=>$rid)) + if(C::t('resources')->update_by_rid($rid,array('vid'=>$vid))){ + + $path = C::t('resources_path')->fetch_pathby_pfid($fileinfo['pfid']); + $path = preg_replace('/dzz:(.+?):/','',$path); + $event = 'edit_versionname'; + $vfilename = DB::result_first("select sval from %t where vid = %d and rid = %s and skey = %s",array('resources_attr',$vid,$fileinfo['rid'],'title')); + $hash = C::t('resources_event')->get_showtpl_hash_by_gpfid($fileinfo['pfid'],$fileinfo['gid']); + $eventdata = array( + 'name' => $vname, + 'filename'=>$fileinfo['name'], + 'username' => $_G['username'], + 'oldvname'=>($fileinfo['name']) ? $fileinfo['name']:dgmdate($fileinfo['dateline'],'Y-m-d H:i:s'), + 'uid' => $_G['uid'], + 'position'=>$path, + 'hash'=>$hash + ); + $statis = array( + 'edits'=>1, + 'uid'=>$_G['uid'], + 'editdateline'=>TIMESTAMP + ); + C::t('resources_statis')->add_statis_by_rid($fileinfo['rid'],$statis); + C::t('resources_event')->addevent_by_pfid($fileinfo['pfid'], $event, 'editversionname', $eventdata, $fileinfo['gid'], $fileinfo['rid'], $fileinfo['name']); + return array('vid'=>$vid,'primaryvid'=>$fileinfo['vid'],'fdateline'=>dgmdate($setarr['dateline'],'Y-m-d H:i:s')); + }else{ + parent::delete($vid); + return array('error'=>lang('explorer_do_failed')); + } + }else{ + return array('error'=>lang('explorer_do_failed')); + } + } + public function get_versioninfo_by_rid_vid($rid,$vid=0){ + $rid = trim($rid); + $vid = intval($vid); + if(!$rid) return ; + if(!$vid){ + return C::t('resources')->fetch_info_by_rid($rid); + } + return DB::fetch_first("select * from %t where rid = %s and vid = %d",array($this->_table,$rid,$vid)); + } + public function fetch_version_by_rid_vid($rid,$vid){ + $rid = trim($rid); + $vid = intval($vid); + $data = array(); + if(!$data = C::t('resources')->fetch_info_by_rid($rid)){ + return $data; + } + $versiondata = DB::fetch_first("select * from %t where rid = %s and vid = %d",array($this->_table,$rid,$vid)); + $data = array_merge($data,$versiondata); + $attrdata = C::t('resources_attr')->fetch_by_rid($rid,$vid); + $data = array_merge($data,$attrdata); + $data['icoid'] = dzzencode('attach::' . $data['aid']); + return $data; + } + +} \ No newline at end of file diff --git a/core/class/table/table_session.php b/core/class/table/table_session.php new file mode 100644 index 0000000..ead39d0 --- /dev/null +++ b/core/class/table/table_session.php @@ -0,0 +1,128 @@ +_table = 'session'; + $this->_pk = 'sid'; + + parent::__construct(); + } + + public function fetch($sid, $ip = false, $uid = false) { + if(empty($sid)) { + return array(); + } + $this->checkpk(); + $session = parent::fetch($sid); + if($session && $ip !== false && $ip != "{$session['ip']}") { + $session = array(); + } + if($session && $uid !== false && $uid != $session['uid']) { + $session = array(); + } + return $session; + } + public function fetch_member($ismember = 0, $invisible = 0, $start = 0, $limit = 0) { + $sql = array(); + if($ismember === 1) { + $sql[] = 'uid > 0'; + } elseif($ismember === 2) { + $sql[] = 'uid = 0'; + } + if($invisible === 1) { + $sql[] = 'invisible = 1'; + } elseif($invisible === 2) { + $sql[] = 'invisible = 0'; + } + $wheresql = !empty($sql) && is_array($sql) ? ' WHERE '.implode(' AND ', $sql) : ''; + $sql = 'SELECT * FROM %t '.$wheresql.' ORDER BY lastactivity DESC'.DB::limit($start, $limit); + return DB::fetch_all($sql, array($this->_table), $this->_pk); + } + + public function count_invisible($type = 1) { + return DB::result_first('SELECT COUNT(*) FROM %t WHERE invisible=%d', array($this->_table, $type)); + } + + public function count($type = 0) { + $condition = $type == 1 ? ' WHERE uid>0 ' : ($type == 2 ? ' WHERE uid=0 ' : ''); + return DB::result_first("SELECT count(*) FROM ".DB::table($this->_table).$condition); + + } + + public function delete_by_session($session, $onlinehold, $guestspan) { + if(!empty($session) && is_array($session)) { + $onlinehold = time() - $onlinehold; + $guestspan = time() - $guestspan; + $session = daddslashes($session); + + $condition = " sid='{$session[sid]}' "; + $condition .= " OR lastactivity<$onlinehold "; + $condition .= " OR (uid='0' AND ".DB::field('ip', $session['ip'])." AND lastactivity>$guestspan) "; + $condition .= $session['uid'] ? " OR (uid='{$session['uid']}') " : ''; + DB::delete('session', $condition); + } + } + public function fetch_by_uid($uid) { + return !empty($uid) ? DB::fetch_first('SELECT * FROM %t WHERE uid=%d', array($this->_table, $uid)) : false; + } + + public function fetch_all_by_uid($uids, $start = 0, $limit = 0) { + $data = array(); + if(!empty($uids)) { + $data = DB::fetch_all('SELECT * FROM %t WHERE '.DB::field('uid', $uids).DB::limit($start, $limit), array($this->_table), null, 'uid'); + } + return $data; + } + + public function update_max_rows($max_rows) { + return DB::query('ALTER TABLE '.DB::table('session').' MAX_ROWS='.dintval($max_rows)); + } + + public function clear() { + return DB::query('DELETE FROM '.DB::table('session')); + } + + public function count_by_fid($fid) { + return ($fid = dintval($fid)) ? DB::result_first('SELECT COUNT(*) FROM '.DB::table('session')." WHERE uid>'0' AND fid='$fid' AND invisible='0'") : 0; + } + + public function fetch_all_by_fid($fid, $limit = 12) { + return ($fid = dintval($fid)) ? DB::fetch_all('SELECT uid, groupid, username, invisible, lastactivity FROM '.DB::table('session')." WHERE uid>'0' AND fid='$fid' AND invisible='0' ORDER BY lastactivity DESC".DB::limit($limit)) : array(); + } + + public function update_by_uid($uid, $data){ + if(($uid = dintval($uid)) && !empty($data) && is_array($data)) { + return DB::update($this->_table, $data, DB::field('uid', $uid)); + } + return 0; + } + + public function count_by_ip($ip) { + $count = 0; + if(!empty($ip)) { + $count = DB::result_first('SELECT COUNT(*) FROM '.DB::table('session')." WHERE ".DB::field('ip', $ip)); + } + return $count; + } + public function fetch_all_by_ip($ip, $start = 0, $limit = 0) { + $data = array(); + if(!empty($ip)) { + $data = DB::fetch_all('SELECT * FROM %t WHERE ip=%s ORDER BY lastactivity DESC'.DB::limit($start, $limit), array($this->_table, $ip), null); + } + return $data; + } +} + +?> diff --git a/core/class/table/table_setting.php b/core/class/table/table_setting.php new file mode 100644 index 0000000..d61ad5c --- /dev/null +++ b/core/class/table/table_setting.php @@ -0,0 +1,79 @@ +_table = 'setting'; + $this->_pk = 'skey'; + + parent::__construct(); + } + + public function fetch($skey, $auto_unserialize = false) { + $data = DB::result_first('SELECT svalue FROM '.DB::table($this->_table).' WHERE '.DB::field($this->_pk, $skey)); + return $auto_unserialize ? (array)unserialize($data) : $data; + } + + public function fetch_all($skeys = array(), $auto_unserialize = false){ + $data = array(); + $where = !empty($skeys) ? ' WHERE '.DB::field($this->_pk, $skeys) : ''; + $query = DB::query('SELECT * FROM '.DB::table($this->_table).$where); + while($value = DB::fetch($query)) { + $data[$value['skey']] = $auto_unserialize ? (array)unserialize($value['svalue']) : $value['svalue']; + } + return $data; + } + + public function update($skey, $svalue){ + return DB::insert($this->_table, array($this->_pk => $skey, 'svalue' => is_array($svalue) ? serialize($svalue) : $svalue), false, true); + } + + public function update_batch($array) { + $settings = array(); + foreach($array as $key => $value) { + $key = addslashes($key); + $value = addslashes(is_array($value) ? serialize($value) : $value); + $settings[] = "('$key', '$value')"; + } + if($settings) { + return DB::query("REPLACE INTO ".DB::table('setting')." (`skey`, `svalue`) VALUES ".implode(',', $settings)); + } + return false; + } + + public function skey_exists($skey) { + return DB::result_first('SELECT skey FROM %t WHERE skey=%s LIMIT 1', array($this->_table, $skey)) ? true : false; + } + + public function fetch_all_not_key($skey) { + return DB::fetch_all('SELECT * FROM '.DB::table($this->_table).' WHERE skey NOT IN('.dimplode($skey).')'); + } + + public function fetch_all_table_status() { + return DB::fetch_all('SHOW TABLE STATUS'); + } + + public function get_tablepre() { + return DB::object()->tablepre; + } + + public function update_count($skey, $num) { + return DB::query("UPDATE %t SET svalue = svalue + %d WHERE skey = %s", array($this->_table, $num, $skey), false, true); + } + + +} + +?> diff --git a/core/class/table/table_shares.php b/core/class/table/table_shares.php new file mode 100644 index 0000000..f9a4942 --- /dev/null +++ b/core/class/table/table_shares.php @@ -0,0 +1,288 @@ +_table = 'shares'; + $this->_pk = 'id'; + parent::__construct(); + } + public function insert($setarr){ + $rid = $setarr['filepath']; + $more = false; + $rids = explode(',',$rid); + $pfids = array(); + foreach(DB::fetch_all("select pfid from %t where rid in(%n)",array('resources',$rids)) as $v){ + $pfids[] = $v['pfid']; + } + $pfids = array_unique($pfids); + if(count($pfids) > 1){ + return array('error'=>lang('Only_allow_sharing_filesinsamedirectory')); + } + $vrid = $rids[0]; + $fileinfo = C::t('resources')->fetch_info_by_rid($vrid); + + $setarr['gid'] = $fileinfo['gid']; + $setarr['pfid'] = $fileinfo['pfid']; + $setarr['dateline'] = time(); + $setarr['uid'] = getglobal('uid'); + $setarr['username'] = getglobal('username'); + if(count($rids) > 1) $more = true; + if($more){ + $fileinfo = C::t('resources')->fetch_by_rid($rids[0]); + $fileinfo['name'] .= '等文件(文件夹)'; + $setarr['type'] = 'url'; + }else{ + $fileinfo = C::t('resources')->fetch_by_rid($rids[0]); + $setarr['type'] = $fileinfo['type']; + } + if($insert = parent::insert($setarr,1)){ + //$share['qrcode'] = self::getQRcodeBySid($insert); + $eventdata = array( + 'username'=>$setarr['username'], + 'filename'=>$fileinfo['name'], + 'url'=>getglobal('siteurl').'index.php?mod=shares&sid='.dzzencode($insert) + ); + if(!C::t('resources_event')->addevent_by_pfid($fileinfo['pfid'],'share_file','share',$eventdata,$fileinfo['gid'],$fileinfo['rid'],$fileinfo['name'])){ + parent::delete($insert); + return array('error'=>lang('create_share_failer')); + }else{ + return array('success'=>$insert); + } + } + } + //更改分享状态 + public function change_by_rid($rid,$status = -3){ + if(!is_array($rid)) $rid = (array)$rid; + $wheresql = '0'; + $params = array($this->_table); + foreach($rid as $v){ + $wheresql .= " or find_in_set(%s,filepath)"; + $params[] = $v; + } + $sids = array(); + foreach(DB::fetch_all("select id from %t where $wheresql",$params) as $v){ + $sids[] = $v['id']; + } + DB::update($this->_table,array('status'=>$status),"id in(".dimplode($sids).")"); + } + //文件进入回收站时,判断相关分享中是否还有对应数据,如果分享包含文件全部删除,改变分享状态 + public function recycle_by_rid($rids){ + if(!is_array($rids)) $rids = (array)$rids; + $params = array($this->_table); + $wheresql = '0'; + foreach($rids as $v){ + $wheresql .= " or find_in_set(%s,filepath)"; + $params[] = $v; + } + $sharedata = DB::fetch_all("select * from %t where $wheresql",$params); + foreach($sharedata as $v){ + $paths = explode(',',$v['filepath']); + if(count($paths) == 1){ + parent::update($v['id'],array('status'=>'-3')); + }else{ + foreach($rids as $val){ + $index = array_search($val,$paths); + if($index === false){ + continue; + }else{ + unset($paths[$index]); + $newpath = implode(',',$paths); + $isdelete = false; + foreach(DB::fecth_all("select isdelete from %t where rid in(%n)",array('resources',$newpath)) as $v){ + if($v['isdelete'] > 0){ + $isdelete = true; + } + } + if($isdelete){ + parent::update($v['id'],array('status'=>'-3')); + } + } + } + } + } + } + //恢复文件时,改变分享状态 + public function recover_file_by_rid($rids){ + if(!is_array($rids)) $rids = (array)$rids; + $params = array($this->_table); + $wheresql = '0'; + foreach($rids as $v){ + $wheresql .= " or find_in_set(%s,filepath)"; + $params[] = $v; + } + $sharedata = DB::fetch_all("select * from %t where $wheresql",$params); + foreach($sharedata as $v){ + $paths = explode(',',$v['filepath']); + foreach($rids as $val){ + $index = array_search($val,$paths); + if($index === false){ + continue; + }else{ + parent::update($v['id'],array('status'=>'0')); + } + + } + } + } + public function fetch_by_path($rid){ + $rid = trim($rid); + if($info = DB::fetch_first("select * from %t where filepath = %s",array($this->_table,$rid))){ + return $info; + } + return false; + } + + public function update_by_id($id,$setarr){ + if(empty($setarr)) return false; + if(!$id) return false; + $rid = $setarr['filepath']; + $more = false; + $rids = explode(',',$rid); + $setarr['dateline'] = time(); + $setarr['uid'] = getglobal('uid'); + $setarr['username'] = getglobal('username'); + if(count($rids) > 1) $more = true; + if($more){ + $fileinfo = C::t('resources')->fetch_info_by_rid($rids[0]); + $fileinfo['name'] .= '等文件(文件夹)'; + }else{ + $fileinfo = C::t('resources')->fetch_info_by_rid($rids[0]); + } + $setarr['gid'] = $fileinfo['gid']; + $setarr['pfid'] = $fileinfo['pfid']; + if(parent::update($id,$setarr)){ + $eventdata = array('username'=>$setarr['username'],'filename'=>$fileinfo['name'],'url'=>getglobal('siteurl').'index.php&mod=shares&sid='.dzzencode($id)); + if(!C::t('resources_event')->addevent_by_pfid($fileinfo['pfid'],'share_file','share',$eventdata,$fileinfo['gid'],$fileinfo['rid'],$fileinfo['name'])){ + parent::delete($id); + return false; + }else{ + return $id; + } + } + } + + public function delete_by_id($id){ + if(!$shareinfo = parent::fetch($id)){ + return array('error'=>lang('share_not_exists')); + } + if(!perm_check::checkperm_Container($shareinfo['pfid'],'share')){ + return array('error'=>lang('no_privilege')); + } + $setarr['dateline'] = time(); + $setarr['uid'] = getglobal('uid'); + $setarr['username'] = getglobal('username'); + if(parent::delete($id)){ + $url = getglobal('siteurl').'index.php?mod=shares&sid='.dzzencode($id); + C::t('shorturl')->delete_by_url($url);//删除短链接 + $eventdata = array('username'=>$setarr['username'],'filename'=>$shareinfo['title']); + C::t('resources_event')->addevent_by_pfid($shareinfo['pfid'],'cancle_share','cancleshare',$eventdata,$shareinfo['gid'],'',$shareinfo['title']); + return array('success'=>true,'shareid'=>$id,'sharetitle'=>$shareinfo['title']); + + }else{ + return array('error'=>lang('explorer_do_failed')); + } + } + //查询当前用户的分享 + public function fetch_all_share_file($limitsql = '',$ordersql = '',$count = false){ + global $_G; + $uid = $_G['uid']; + $params = array($this->_table); + $wheresql = ' uid = %d'; + $params[] = $uid; + $orgids = C::t('organization')->fetch_all_orgid();//获取所有有管理权限的部门(); + $manageorgids = $orgids['orgids_admin']; + if(!empty($manageorgids)){ + $wheresql .= ' or gid in(%n)'; + $params[] = $manageorgids; + } + $shareinfo = array(); + if($count){ + return DB::result_first("select count(*) from %t where $wheresql $ordersql ",$params); + } + $sharestatus = array('-5'=>lang('sharefile_isdeleted_or_positionchange'),'-4' => lang('been_blocked'), '-3' => lang('file_been_deleted'), '-2' => lang('degree_exhaust'), '-1' => lang('logs_invite_status_4'), '0' => lang('founder_upgrade_normal')); + foreach(DB::fetch_all("select * from %t where $wheresql $ordersql $limitsql",$params) as $val){ + $val['sharelink'] = outputurl(getglobal('siteurl').'index.php?mod=shares&sid='.dzzencode($val['id'])); + $val['fdateline'] = dgmdate($val['dateline'],'Y-m-d H:i:s'); + $val['password'] = ($val['password']) ? dzzdecode($val['password']):''; + $sid = dzzencode($val['id']); + if(is_file($_G['setting']['attachdir'].'./qrcode/'.$sid[0].'/'.$sid.'.png')){ + $val['qrcode']=$_G['setting']['attachurl'].'./qrcode/'.$sid[0].'/'.$sid.'.png'; + }else{ + $val['qrcode'] = self::getQRcodeBySid($sid); + } + if($val['endtime']){ + $timediff = ($val['endtime'] - $val['dateline']); + $days = 0; + if($timediff > 0){ + $days = ceil($timediff/86400); + } + $val['expireday'] = ($days > 0) ? $days.'天后':'已过期'; + }else{ + $val['expireday'] = '永久有效'; + } + $rids = explode(',',$val['filepath']); + if(count($rids) > 1){ + $val['img'] = '/dzz/explorer/img/ic-files.png'; + }else{ + $val['img'] = C::t('resources')->get_icosinfo_by_rid($val['filepath']); + } + $val['name'] = $val['title']; + $val['rid'] = $val['id']; + $val['shared'] = true; + //检查文件是否被恢复 + if($val['status'] == -3){ + $isdelete = false; + foreach(DB::fetch_all("select isdelete from %t where rid in(%n)",array('resources',$rids)) as $v){ + if($v['isdelete'] > 0){ + $isdelete = true; + } + } + if(!$isdelete){ + DB::update($this->_table,array('status'=>0),array('id'=>$val['id'])); + $val['status'] = 0; + } + } + //检查文件是否移动 + if($val['status'] == -5){ + $ischange = false; + $pfids = array(); + foreach(DB::fetch_all("select pfid from %t where rid in(%n)",array('resources',$rids)) as $v){ + $pfids[] = $v['pfid']; + } + $pfids = array_unique($pfids); + if(count($pfids) < 2 && $pfids[0] == $val['pfid']){ + DB::update($this->_table,array('status'=>0),array('id'=>$val['id'])); + $val['status'] = 0; + } + } + $val['fstatus'] = $sharestatus[$val['status']]; + $shareinfo[$val['rid']] = $val; + } + return $shareinfo; + } + public function getQRcodeBySid($sid){ + $target='./qrcode/'.$sid[0].'/'.$sid.'.png'; + $targetpath = dirname(getglobal('setting/attachdir').$target); + dmkdir($targetpath); + if(@getimagesize(getglobal('setting/attachdir').$target)){ + return getglobal('setting/attachurl').$target; + }else{//生成二维码 + QRcode::png((getglobal('siteurl').'index.php?mod=shares&sid='.$sid),getglobal('setting/attachdir').$target,'M',4,2); + return getglobal('setting/attachurl').$target; + } + } + //增加浏览次数 + public function add_views_by_id($id){ + return DB::query("update %t set views=views+1,count=count+1 where id = %d",array($this->_table,$id)); + } + //增加下载次数 + public function add_downs_by_id($id){ + return DB::query("update %t set downs=downs+1 where id=%d",array($this->_table,$id)); + } +} \ No newline at end of file diff --git a/core/class/table/table_shorturl.php b/core/class/table/table_shorturl.php new file mode 100644 index 0000000..4be8d82 --- /dev/null +++ b/core/class/table/table_shorturl.php @@ -0,0 +1,66 @@ +_table = 'shorturl'; + $this->_pk = 'sid'; + $this->_pre_cache_key = 'shorturl_'; + $this->_cache_ttl =0; + parent::__construct(); + } + + private function code62($x) { + $show = ''; + while($x > 0) { + $s = $x % 62; + if ($s > 35) { + $s = chr($s+61); + } elseif ($s > 9 && $s <=35) { + $s = chr($s + 55); + } + $show .= $s; + $x = floor($x/62); + } + return $show; + } + public function getSid($url) { + $url = crc32($url); + $result = sprintf("%u", $url); + return self::code62($result); + } + + public function getShortUrl($url){ + $sid=self::getSid($url); + if(DB::result_first("select COUNT(*) from %t where sid=%s",array($this->_table,$sid))){ + return getglobal('siteurl').'short.php?sid='.$sid; + } + $setarr=array('sid'=>$sid, + 'url'=>$url, + ); + if(parent::insert($setarr)){ + return getglobal('siteurl').'short.php?sid='.$sid; + } + return ''; + } + public function addview($sid){ + return DB::query("update %t set count=count+1 where sid=%s",array($this->_table,$sid)); + } + public function delete_by_url($url){ + $sid=self::getSid($url); + return parent::delete($sid); + } +} +?> diff --git a/core/class/table/table_smiley.php b/core/class/table/table_smiley.php new file mode 100644 index 0000000..ad20494 --- /dev/null +++ b/core/class/table/table_smiley.php @@ -0,0 +1,104 @@ +_table = 'smiley'; + $this->_pk = 'id'; + + parent::__construct(); + } + public function fetch_all_by_type($type) { + $type = $this->checktype($type); + if(empty($type)) { + return array(); + } + $typesql = is_array($type) ? 'type IN(%n)' : 'type=%s'; + return DB::fetch_all("SELECT * FROM %t WHERE $typesql ORDER BY displayorder", array($this->_table, $type), $this->_pk); + } + + public function fetch_all_by_typeid_type($typeid, $type, $start = 0, $limit = 0) { + return DB::fetch_all('SELECT * FROM %t WHERE typeid=%d AND type=%s ORDER BY displayorder '.DB::limit($start, $limit), array($this->_table, $typeid, $type), $this->_pk); + } + public function fetch_all_by_type_code_typeid($type, $typeid) { + return DB::fetch_all("SELECT * FROM %t WHERE type=%s AND code<>'' AND typeid=%d ORDER BY displayorder ", array($this->_table, $type, $typeid), $this->_pk); + } + public function fetch_all_cache() { + return DB::fetch_all("SELECT s.id, s.code, s.url, t.typeid FROM %t s INNER JOIN %t t ON t.typeid=s.typeid WHERE s.type='smiley' AND s.code<>'' AND t.available='1' ORDER BY LENGTH(s.code) DESC", array($this->_table, 'imagetype')); + + } + public function fetch_by_id_type($id, $type) { + return DB::fetch_first('SELECT * FROM %t WHERE id=%d AND type=%s', array($this->_table, $id, $type), $this->_pk); + } + public function update_by_type($type, $data) { + if(!empty($data) && is_array($data) && in_array($type, $this->allowtype)) { + return DB::update($this->_table, $data, DB::field('type', $type)); + } + return 0; + } + public function update_by_id_type($id, $type, $data) { + $id = dintval($id, true); + if(!empty($data) && is_array($data) && $id && in_array($type, $this->allowtype)) { + return DB::update($this->_table, $data, DB::field('id', $id).' AND '.DB::field('type', $type)); + } + return 0; + } + public function update_code_by_typeid($typeid) { + $typeid = dintval($typeid, true); + if(empty($typeid)) { + return 0; + } + $typeidsql = is_array($typeid) ? 'typeid IN(%n)' : 'typeid=%d'; + return DB::query("UPDATE %t SET code=CONCAT('{:', typeid, '_', id, ':}') WHERE $typeidsql", array($this->_table, $typeid)); + } + public function update_code_by_id($ids) { + $ids = dintval($ids, true); + if(empty($ids)) { + return 0; + } + $idssql = is_array($ids) ? 'id IN(%n)' : 'id=%d'; + return DB::query("UPDATE %t SET code=CONCAT('{:', typeid, '_', id, ':}') WHERE $idssql", array($this->_table, $ids)); + } + public function count_by_type($type) { + $type = $this->checktype($type); + if(empty($type)) { + return 0; + } + return DB::result_first('SELECT COUNT(*) FROM %t WHERE type IN(%n)', array($this->_table, $type)); + } + public function count_by_typeid($typeid) { + return DB::result_first('SELECT COUNT(*) FROM %t WHERE typeid=%d', array($this->_table, $typeid)); + } + public function count_by_type_typeid($type, $typeid) { + $typeid = dintval($typeid, true); + if(!empty($typeid) && in_array($type, $this->allowtype)) { + return DB::result_first('SELECT COUNT(*) FROM %t WHERE type=%s AND typeid IN(%n)', array($this->_table, $type, $typeid)); + } + return 0; + } + public function count_by_type_code_typeid($type, $typeid) { + return DB::result_first("SELECT COUNT(*) FROM %t WHERE type=%s AND code<>'' AND typeid=%d", array($this->_table, $type, $typeid)); + } + + private function checktype($type) { + if(is_array($type)) { + foreach($type as $key => $val) { + if(!in_array($val, $this->allowtype)) { + unset($type[$key]); + } + } + } else { + $type = in_array($type, $this->allowtype) ? $type : ''; + } + return $type; + } + +} + +?> \ No newline at end of file diff --git a/core/class/table/table_syscache.php b/core/class/table/table_syscache.php new file mode 100644 index 0000000..dd290da --- /dev/null +++ b/core/class/table/table_syscache.php @@ -0,0 +1,115 @@ +_table = 'syscache'; + $this->_pk = 'cname'; + $this->_pre_cache_key = ''; + $this->_isfilecache = getglobal('config/cache/type') == 'file'; + $this->_allowmem = memory('check'); + + parent::__construct(); + } + + public function fetch($cachename) { + $data = $this->fetch_all(array($cachename)); + return isset($data[$cachename]) ? $data[$cachename] : false; + } + public function fetch_all($cachenames) { + + $data = array(); + $cachenames = is_array($cachenames) ? $cachenames : array($cachenames); + if($this->_allowmem) { + $data = memory('get', $cachenames); + $newarray = $data !== false ? array_diff($cachenames, array_keys($data)) : $cachenames; + if(empty($newarray)) { + return $data; + } else { + $cachenames = $newarray; + } + } + + if($this->_isfilecache) { + $lostcaches = array(); + foreach($cachenames as $cachename) { + if(!@include_once(DZZ_ROOT.'./data/cache/cache_'.$cachename.'.php')) { + $lostcaches[] = $cachename; + } elseif($this->_allowmem) { + memory('set', $cachename, $data[$cachename]); + } + } + if(!$lostcaches) { + return $data; + } + $cachenames = $lostcaches; + unset($lostcaches); + } + + $query = DB::query('SELECT * FROM '.DB::table($this->_table).' WHERE '.DB::field('cname', $cachenames)); + while($syscache = DB::fetch($query)) { + $data[$syscache['cname']] = $syscache['ctype'] ? unserialize($syscache['data']) : $syscache['data']; + $this->_allowmem && (memory('set', $syscache['cname'], $data[$syscache['cname']])); + if($this->_isfilecache) { + $cachedata = '$data[\''.$syscache['cname'].'\'] = '.var_export($data[$syscache['cname']], true).";\n\n"; + if(($fp = @fopen(DZZ_ROOT.'./data/cache/cache_'.$syscache['cname'].'.php', 'wb'))) { + fwrite($fp, ""); + fclose($fp); + } + } + } + + foreach($cachenames as $name) { + if($data[$name] === null) { + $data[$name] = null; + $this->_allowmem && (memory('set', $name, array())); + } + } + + return $data; + } + + public function insert($cachename, $data) { + parent::insert(array( + 'cname' => $cachename, + 'ctype' => is_array($data) ? 1 : 0, + 'dateline' => TIMESTAMP, + 'data' => is_array($data) ? serialize($data) : $data, + ), false, true); + + if($this->_allowmem && memory('get', $cachename) !== false) { + memory('set', $cachename, $data); + } + $this->_isfilecache && @unlink(DZZ_ROOT.'./data/cache/cache_'.$cachename.'.php'); + } + + public function update($cachename, $data,$unbuffered = false, $low_priority = false) { + $this->insert($cachename, $data); + } + + public function delete($cachenames,$unbuffered = false) { + parent::delete($cachenames); + if($this->_allowmem || $this->_isfilecache) { + foreach((array)$cachenames as $cachename) { + $this->_allowmem && memory('rm', $cachename); + $this->_isfilecache && @unlink(DZZ_ROOT.'./data/cache/cache_'.$cachename.'.php'); + } + } + } +} + +?> diff --git a/core/class/table/table_tag.php b/core/class/table/table_tag.php new file mode 100644 index 0000000..1536422 --- /dev/null +++ b/core/class/table/table_tag.php @@ -0,0 +1,70 @@ +_table = 'tag'; + $this->_pk = 'tid'; + parent::__construct(); + } + public function insert_data($tags,$idtype=''){ + if(!is_array($tags)) $tags = (array)$tags; + $tids = array(); + foreach($tags as $v){ + if(preg_match('/^\s*$/',$v)) continue; + if($result = DB::fetch_first("select tid from %t where idtype = %s and tagname = %s",array($this->_table,$idtype,$v))){ + $tids[$result['tid']] = array('tid'=>$result['tid'],'tagname'=>$v); + }else{ + $setarr = array( + 'tagname'=>$v, + 'uid'=>getglobal('uid'), + 'username'=>getglobal('username'), + 'idtype'=>$idtype, + 'hot' =>0 + ); + $tid = parent::insert($setarr,1); + $tids[$tid] = array('tid'=>$tid,'tagname'=>$v); + } + } + return $tids; + } + public function addhot_by_tid($tid,$hot = 1){ + if(!is_array($tid)) $tid=array($tid); + if($hot>0){ + DB::query("update %t set hot=hot+%d where tid IN(%n)",array($this->_table,$hot,$tid)); + }else{ + DB::query("update %t set hot=hot-%d where tid IN(%n)",array($this->_table,abs($hot),$tid)); + } + } + + public function fetch_tag_by_tid($tids,$idtype){ + if(!is_array($tids)) $tids = (array)$tids; + return DB::fetch_all("select tagname,tid from %t where tid in(%n) and idtype = %s ",array($this->_table,$tids,$idtype)); + } + public function fetch_tid_by_tagname($tagnames,$idtype){ + if(!is_array($tagnames)) $tagnames = (array)$tagnames; + $searchtag = array(); + foreach ($tagnames as $v){ + $searchtag[] = trim($v); + } + $tids = array(); + foreach(DB::fetch_all("select tid from %t where tagname in(%n) and idtype=%s",array($this->_table,$searchtag,$idtype)) as $v){ + $tids[] = $v['tid']; + } + if(count($tagnames) != count($tids)){ + $tids = array(); + } + return $tids; + } + public function fetch_tag_byidtype($idtype,$limit=10){ + $tags = array(); + if(!$idtype) return $tags; + $tags = DB::fetch_all("select tid,tagname from %t where idtype=%s order by hot limit 0,$limit",array($this->_table,$idtype)); + return $tags; + } +} \ No newline at end of file diff --git a/core/class/table/table_thame.php b/core/class/table/table_thame.php new file mode 100644 index 0000000..f1a9b18 --- /dev/null +++ b/core/class/table/table_thame.php @@ -0,0 +1,25 @@ +_table = 'thame'; + $this->_pk = 'id'; + + parent::__construct(); + } +} + +?> diff --git a/core/class/table/table_user.php b/core/class/table/table_user.php new file mode 100644 index 0000000..1a17021 --- /dev/null +++ b/core/class/table/table_user.php @@ -0,0 +1,582 @@ +_table = 'user'; + $this->_pk = 'uid'; + $this->_pre_cache_key = 'user_'; + + parent::__construct(); + } + /*public function fetch_safebindstatus($uid){ + $uid = intval($uid); + $result = DB::fetch_first("select emailstatus,phonestatus from %t where uid = %d",array($this->_table,$uid)); + return $result; + }*/ + public function add_user($userArr){ + + global $_G; + + if(empty($userArr)) return ; + $salt=substr(uniqid(rand()), -6); + $groupid = ''; + if($_G['setting']['regverify']) { + $groupid = 8; + } else { + $groupid =$_G['setting']['newusergroupid']; + } + $setarr=array( + 'username'=>addslashes($userArr['username']), + 'email'=>isset($userArr['email']) ? $userArr['email']:'' , + 'salt'=>$salt, + 'password'=>md5(md5($userArr['password']).$salt), + 'regdate'=>TIMESTAMP, + 'regip'=>$_G['clientip'], + 'groupid'=>$groupid + ); + $setarr['uid'] = parent::insert($setarr,1); + return $setarr; + } + public function update_password($uid,$password){ + $uid = intval($uid); + if(parent::update($uid,array('password'=>$password))){ + return true; + } + return false; + } + public function user_register($userArr,$addorg = 1){ + + if(empty($userArr)) return ; + + if($userArr['username'] && ($status = uc_user_checkname($userArr['username'])) < 0) { + return $status; + } + + if(($status = uc_user_checkemail($userArr['email'])) < 0) { + + return $status; + } + + $uid =self::add_user($userArr); + + //默认机构 + if($addorg && is_array($uid) && getglobal('setting/defaultdepartment') && DB::fetch_first("select orgid from %t where orgid=%d ",array('organization',getglobal('setting/defaultdepartment')))){ + C::t('organization_user')->insert_by_orgid(getglobal('setting/defaultdepartment'),$uid['uid']); + } + + return $uid; + } + public function delete_by_uid($uid){ + $user=parent::fetch($uid); + if(self::checkfounder($user)){//创始人不能删除 + return false; + } + if(parent::delete($uid)){ + C::t('user_field')->delete($uid); + C::t('user_profile')->delete($uid); + C::t('user_status')->delete($uid); + C::t('user_setting')->delete_by_uid($uid); + C::t('organization_user')->delete_by_uid($uid,0); + DB::delete('user_qqconnect',"uid='{$uid}'"); //删除QQ登陆 + + //删除用户文件 + if($homefid=DB::result_first("select fid from %t where uid=%d and flag='home' ",array('folder',$uid))){ + C::t('folder')->delete_by_fid($homefid,true); + } + + Hook::listen('syntoline_user',$uid,'del');//删除对应到三方用户表 + return true; + } + return false; + } + public function checkfounder($user) { + + $founders = str_replace(' ', '', getglobal('config/admincp/founder')); + if(!$user['uid'] || $user['groupid'] != 1 || $user['adminid'] != 1 ) { + return false; + } elseif(empty($founders)) { + return false; + } elseif(strexists(",$founders,", ",$user[uid],")) { + return true; + } elseif(!is_numeric($user['nickname']) && strexists(",$founders,", ",$user[nickname],")) { + return true; + } else { + return false; + } + } + public function setAdministror($uid,$groupid){ + $user=getuserbyuid($uid); + //if($user['adminid']==$adminid) return true; + if(self::checkfounder($user)){ //创始人不允许修改 + return true; + } + $arr=array(); + if($groupid==1){ + parent::update($uid,array('adminid'=>1,'groupid'=>1)); + }else{ + if(empty($groupid)) $groupid=9; + /*if(C::t('organization_admin')->fetch_orgids_by_uid($uid)){ + $groupid=2; + }*/ + parent::update($uid,array('adminid'=>0,'groupid'=>$groupid)); + } + } + public function update_credits($uid, $credits) { + if($uid) { + $data = array('credits'=>intval($credits)); + DB::update($this->_table, $data, array('uid' => intval($uid)), 'UNBUFFERED'); + $this->update_cache($uid, $data); + } + } + + public function update_by_groupid($groupid, $data) { + $uids = array(); + $groupid = dintval($groupid, true); + if($groupid && $this->_allowmem) { + $uids = array_keys($this->fetch_all_by_groupid($groupid)); + } + if($groupid && !empty($data) && is_array($data)) { + DB::update($this->_table, $data, DB::field('groupid', $groupid), 'UNBUFFERED'); + } + if($uids) { + $this->update_cache($uids, $data); + } + } + + public function fetch_userbasic_by_uid($uid){ + + return DB::fetch_first("select uid,email,username from %t where uid = %d",array($this->_table,$uid)); + } + + public function increase($uids, $setarr) { + $uids = dintval((array)$uids, true); + $sql = array(); + $allowkey = array('newprompt'); + foreach($setarr as $key => $value) { + if(($value = intval($value)) && in_array($key, $allowkey)) { + $sql[] = "`$key`=`$key`+'$value'"; + } + } + if(!empty($sql)){ + DB::query("UPDATE ".DB::table($this->_table)." SET ".implode(',', $sql)." WHERE uid IN (".dimplode($uids).")", 'UNBUFFERED'); + $this->increase_cache($uids, $setarr); + } + } + + + + public function fetch_all_by_username($usernames, $fetch_archive = 1) { + $users = array(); + if(!empty($usernames)) { + $users = DB::fetch_all('SELECT * FROM %t WHERE username IN (%n)', array($this->_table, (array)$usernames), 'username'); + } + return $users; + } + /* + * 新增 + * 以uid查询用户数据 + * **/ + public function get_user_by_uid($uid){ + + $uid = intval($uid); + + static $users = array(); + + if($uid && empty($users[$uid])) { + + $users[$uid] = DB::fetch_first("select * from %t where uid = %d",array($this->_table,$uid)); + } + + if($users[$uid]['adminid']==1) $users[$uid]['self'] = 2; + + return $users[$uid]; + + } + + public function fetch_uid_by_username($username, $fetch_archive = 0) { + $uid = 0; + if($username) { + $uid = DB::result_first('SELECT uid FROM %t WHERE username=%s', array($this->_table, $username)); + } + return $uid; + } + + public function fetch_all_uid_by_username($usernames, $fetch_archive = 1) { + $uids = array(); + if($usernames) { + foreach($this->fetch_all_by_username($usernames, $fetch_archive) as $username => $value) { + $uids[$username] = $value['uid']; + } + } + return $uids; + } + + public function fetch_all_by_adminid($adminids, $fetch_archive = 1) { + $users = array(); + $adminids = dintval((array)$adminids, true); + if($adminids) { + $users = DB::fetch_all('SELECT * FROM %t WHERE adminid IN (%n) ORDER BY adminid, uid', array($this->_table, (array)$adminids), $this->_pk); + } + return $users; + } + + public function fetch_all_username_by_uid($uids) { + $users = array(); + if(($uids = dintval($uids, true))) { + foreach($this->fetch_all($uids) as $uid => $value) { + $users[$uid] = $value['username']; + } + } + return $users; + } + + public function count_by_groupid($groupid) { + return $groupid ? DB::result_first('SELECT COUNT(*) FROM %t WHERE '.DB::field('groupid', $groupid), array($this->_table)) : 0; + } + + public function fetch_all_by_groupid($groupid, $start = 0, $limit = 0) { + $users = array(); + if(($groupid = dintval($groupid, true))) { + $users = DB::fetch_all('SELECT * FROM '.DB::table($this->_table).' WHERE '.DB::field('groupid', $groupid).' '.DB::limit($start, $limit), null, 'uid'); + } + return $users; + } + + public function fetch_all_groupid() { + return DB::fetch_all('SELECT DISTINCT(groupid) FROM '.DB::table($this->_table), null, 'groupid'); + } + + public function fetch_all_by_allowadmincp($val, $glue = '=') { + return DB::fetch_all('SELECT * FROM '.DB::table($this->_table).' WHERE '.DB::field('allowadmincp', intval($val), $glue), NULL, 'uid'); + } + + public function update_admincp_manage($uids) { + if(($uids = dintval($uids, true))) { + $data = DB::query('UPDATE '.DB::table($this->_table).' SET allowadmincp=allowadmincp | 1 WHERE uid IN ('.dimplode($uids).')'); + $this->reset_cache($uids); + return $data; + } + return false; + } + + public function clean_admincp_manage($uids) { + if(($uids = dintval($uids, true))) { + $data = DB::query('UPDATE '.DB::table($this->_table).' SET allowadmincp=allowadmincp & 0xFE WHERE uid IN ('.dimplode($uids).')'); + $this->reset_cache($uids); + return $data; + } + return false; + } + public function chk_email_by_uid($email,$uid){ + + if(parent::fetch_all("select uid from %t where email = %s and uid != %d",array($this->_table,$email,$uid))){ + + return true; + } + + return false; + } + public function fetch_by_email($email, $fetch_archive = 0) { + $user = array(); + if($email) { + $user = DB::fetch_first('SELECT * FROM %t WHERE email=%s', array($this->_table, $email)); + } + return $user; + } + public function fetch_by_username($username, $fetch_archive = 0) { + $user = array(); + if($username) { + $user = DB::fetch_first('SELECT * FROM %t WHERE username=%s', array($this->_table, $username)); + } + return $user; + } + public function fetch_by_nickname($username, $fetch_archive = 0) { + + $user = array(); + if($username) { + $user = DB::fetch_first('SELECT * FROM %t WHERE nickname=%s', array($this->_table, $username)); + } + return $user; + } + public function fetch_by_phone($username, $fetch_archive = 0) { + + $user = array(); + if($username) { + $user = DB::fetch_first('SELECT * FROM %t WHERE phone=%s', array($this->_table, $username)); + } + return $user; + } + public function fetch_by_weixinid($username, $fetch_archive = 0) { + + $user = array(); + if($username) { + $user = DB::fetch_first('SELECT * FROM %t WHERE weixinid=%s', array($this->_table, $username)); + } + return $user; + } + public function fetch_by_wechat_userid($username, $fetch_archive = 0) { + + $user = array(); + if($username) { + $user = DB::fetch_first('SELECT * FROM %t WHERE wechat_userid=%s', array($this->_table, $username)); + } + return $user; + } + public function fetch_by_uid($uid, $fetch_archive = 0) { + $user = array(); + if($uid) { + $user = DB::fetch_first('SELECT * FROM %t WHERE uid=%d', array($this->_table, $uid)); + } + return $user; + } + + public function fetch_all_by_email($emails, $fetch_archive = 1) { + $users = array(); + if(!empty($emails)) { + $users = DB::fetch_all('SELECT * FROM %t WHERE %i', array($this->_table, DB::field('email', $emails)), 'email'); + } + return $users; + } + + public function count_by_email($email, $fetch_archive = 0) { + $count = 0; + if($email) { + $count = DB::result_first('SELECT COUNT(*) FROM %t WHERE email=%s', array($this->_table, $email)); + } + return $count; + } + + public function fetch_all_by_like_username($username, $start = 0, $limit = 0) { + $data = array(); + if($username) { + $data = DB::fetch_all('SELECT * FROM %t WHERE username LIKE %s'.DB::limit($start, $limit), array($this->_table, stripsearchkey($username).'%'), 'uid'); + } + return $data; + } + + public function count_by_like_username($username) { + return !empty($username) ? DB::result_first('SELECT COUNT(*) FROM %t WHERE username LIKE %s', array($this->_table, stripsearchkey($username).'%')) : 0; + } + + + public function fetch_runtime() { + return DB::result_first("SELECT (MAX(regdate)-MIN(regdate))/86400 AS runtime FROM ".DB::table($this->_table)); + } + + public function count_admins() { + return DB::result_first("SELECT COUNT(*) FROM ".DB::table($this->_table)." WHERE adminid<>'0' AND adminid<>'-1'"); + } + + public function count_by_regdate($timestamp) { + return DB::result_first('SELECT COUNT(*) FROM %t WHERE regdate>%d', array($this->_table, $timestamp)); + } + //根据用户组id,查询用户id + public function fetch_uid_by_groupid($groupid){ + $groupid = intval($groupid); + return DB::fetch_all("select uid from %t where groupid = %d",array($this->_table,$groupid)); + } + + public function fetch_all_stat_memberlist($username, $orderby = '', $sort = '', $start = 0, $limit = 0) { + $orderby = in_array($orderby, array('uid','credits','regdate', 'gender','username','posts','lastvisit'), true) ? $orderby : 'uid'; + $sql = ''; + + $sql = !empty($username) ? " WHERE username LIKE '".addslashes(stripsearchkey($username))."%'" : ''; + + $memberlist = array(); + $query = DB::query("SELECT m.uid, m.username, mp.gender, m.email, m.regdate, ms.lastvisit, mc.posts, m.credits + FROM ".DB::table($this->_table)." m + LEFT JOIN ".DB::table('user_profile')." mp ON mp.uid=m.uid + LEFT JOIN ".DB::table('user_status')." ms ON ms.uid=m.uid + $sql ORDER BY ".DB::order($orderby, $sort).DB::limit($start, $limit)); + while($member = DB::fetch($query)) { + $member['usernameenc'] = rawurlencode($member['username']); + $member['regdate'] = dgmdate($member['regdate']); + $member['lastvisit'] = dgmdate($member['lastvisit']); + $memberlist[$member['uid']] = $member; + } + return $memberlist; + } + + + + public function insert($uid, $ip, $groupid, $extdata, $adminid = 0) { + if(($uid = dintval($uid))) { + $profile = isset($extdata['profile']) ? $extdata['profile'] : array(); + //$profile['uid'] = $uid; + $base = array( + 'uid' => $uid, + 'adminid' => intval($adminid), + 'groupid' => intval($groupid), + 'regdate' => TIMESTAMP, + 'emailstatus' => intval($extdata['emailstatus']), + + ); + $status = array( + 'uid' => $uid, + 'regip' => (string)$ip, + 'lastip' => (string)$ip, + 'lastvisit' => TIMESTAMP, + 'lastactivity' => TIMESTAMP, + 'lastsendmail' => 0 + ); + + $ext = array('uid' => $uid); + parent::update($uid,$base); + C::t('user_status')->insert($status, false, true); + C::t('user_profile')->update($uid,$profile); + } + } + public function insert_user($userarr,$groupid = 9,$profilearr=array()){ + global $_G; + if(empty($userarr)){ + return false; + } + $ip = $_G['clientip']; + $salt=substr(uniqid(rand()), -6); + $setarr=array( + 'username'=>addslashes($userarr['username']), + 'email'=>$userarr['email'], + 'salt'=>$salt, + 'password'=>md5(md5($userarr['password']).$salt), + 'regdate'=>TIMESTAMP, + 'regip'=>$ip, + 'groupid'=>$groupid, + 'phone'=>$userarr['phone'], + 'phonestatus'=>$userarr['phonestatus'] + ); + $uid = parent::insert($setarr,1); + if($uid){ + $status = array( + 'uid' => $uid, + 'regip' => (string)$ip, + 'lastip' => (string)$ip, + 'lastvisit' => TIMESTAMP, + 'lastactivity' => TIMESTAMP, + 'lastsendmail' => 0 + ); + C::t('user_status')->insert($status,1); + if(!empty($profilearr)){ + C::t('user_profile')->update($uid,$profilearr); + } + $setarr['uid'] = $uid; + return $setarr; + }else{ + return false; + } + + + + } + public function insert_user_setarr($setarr){ + if(empty($setarr)) return ; + return parent::insert($setarr,1); + } + + public function delete($val, $unbuffered = false, $fetch_archive = 0) { + $ret = false; + + if(($val = dintval($val, true))) { + foreach((array)$val as $key=> $uid) { + if($uid==1) unset($val[$key]); //暂时限制uid=1的用户不允许删除 + } + $ret = parent::delete($val, $unbuffered, $fetch_archive); + if($this->_allowmem) { + $data = ($data = memory('get', 'deleteuids')) === false ? array() : $data; + foreach((array)$val as $uid) { + $data[$uid] = $uid; + } + memory('set', 'deleteuids', $data, 86400*2); + } + } + return $ret; + } + + public function max_uid() { + return DB::result_first('SELECT MAX(uid) FROM %t', array($this->_table)); + } + + public function range_by_uid($from, $limit) { + return DB::fetch_all('SELECT * FROM %t WHERE uid >= %d ORDER BY uid LIMIT %d', array($this->_table, $from, $limit), $this->_pk); + } + + public function update_groupid_by_groupid($source, $target) { + return DB::query('UPDATE %t SET groupid=%d WHERE adminid <= 0 AND groupid=%d', array($this->_table, $target, $source)); + } + public function fetch_all_user(){ + return DB::fetch_all("select * from %t",array($this->_table)); + } + //获取用户独享空间配置值,若未分配,则获取用户已使用空间 + public function get_allotspace(){ + global $_G; + $setting = $_G['setting']; + $userallotspace = 0; + $uids = array(); + foreach(DB::fetch_all("select uid from %t",array($this->_table)) as $v){ + $uids[] = $v['uid']; + } + foreach(DB::fetch_all("select userspace,usesize from %t where uid in(%n)",array('user_field',$uids)) as $val){ + if($val['userspace'] > 0){ + $userallotspace += $val['userspace']*1024*1024; + }else{ + $userallotspace += $val['usesize']; + } + } + return $userallotspace; + } + //获取用户信息包含头像信息 + public function fetch_user_avatar_by_uids($uids){ + if(!is_array($uids)) $uids = array($uids); + $uids = array_unique($uids); + $users = array(); + foreach(DB::fetch_all("select u.*,s.svalue from %t u left join %t s on u.uid=s.uid and s.skey=%s where u.uid in(%n)",array('user','user_setting','headerColor',$uids)) as $v){ + if($v['avatarstatus'] == 1){ + $v['avatarstatus'] = 1; + }else{ + $v['avatarstatus'] = 0; + $v['headerColor'] = $v['svalue']; + } + $users[$v['uid']] = $v; + } + + return $users; + } + public function fetch_userinfo_detail_by_uid($uid){ + $uid = intval($uid); + $users = DB::fetch_first("select u.uid,u.phone,u.email,ug.* from %t u left join %t ug on u.groupid=ug.groupid where uid = %d",array('user','usergroup',$uid)); + foreach(DB::fetch_all("select * from %t where uid = %d",array('user_profile',$uid)) as $v){ + if(!$v['privacy']){ + $users['information'][$v['fieldid']] = $v['value']; + } + } + return $users; + } + public function fetch_all_user_data(){ + return DB::fetch_all("select * from %t where 1",array($this->_table)); + } + /*//获取用户信息,包含资料等信息 + public function fetch_user_infomessage_by_uid($uid){ + $users = array(); + foreach(DB::fetch_all("select u.*,s.svalue from %t u left join %t s on u.uid=s.uid and s.skey=%s where u.uid =%d",array('user','user_setting','headerColor',$uid)) as $v){ + if($v['avatarstatus'] == 1){ + $v['avatarstatus'] = 1; + }else{ + $v['avatarstatus'] = 0; + $v['headerColor'] = $v['svalue']; + } + $users[$v['uid']] = $v; + } + + return $users; + }*/ +} diff --git a/core/class/table/table_user_field.php b/core/class/table/table_user_field.php new file mode 100644 index 0000000..2d4f054 --- /dev/null +++ b/core/class/table/table_user_field.php @@ -0,0 +1,25 @@ +_table = 'user_field'; + $this->_pk = 'uid'; + $this->_pre_cache_key = 'user_field_'; + $this->_cache_ttl = 60*60; + + parent::__construct(); + } +} diff --git a/core/class/table/table_user_profile.php b/core/class/table/table_user_profile.php new file mode 100644 index 0000000..e808ab9 --- /dev/null +++ b/core/class/table/table_user_profile.php @@ -0,0 +1,206 @@ +_table = 'user_profile'; + $this->_pk = 'uid'; + //$this->_pre_cache_key = 'user_profile_'; + parent::__construct(); + } + public function get_userprofile_by_uid($uid){ + global $_G; + $uid = $uid ? intval($uid):''; + if(!$uid) return false; + $values = array(); + if($values = C::t('user')->get_user_by_uid($uid)){ + $var = 'user_{$uid}_profile'; + if(($_G[$var] = self::fetch($uid)) !== false){ + if(!empty($_G[$var]['department'])){ + $_G[$var]['department_tree']=C::t('organization')->getPathByOrgid(intval($_G[$var]['department'])); + }else{ + $_G[$var]['department_tree']=lang('please_select_a_organization_or_department'); + } + }else{ + $_G[$var] = array(); + } + $values = array_merge($values,$_G[$var]); + } + return $values; + } + public function get_user_info_by_uid($uid){ + global $_G; + $uid = $uid ? intval($uid):''; + $info = array(); + foreach($result = DB::fetch_all("select * from %t where uid =%d",array($this->_table,$uid)) as $value){ + $info[$value['fieldid']] = $value['value']; + $info['privacy']['profile'][$value['fieldid']] = $value['privacy']; + } + $var = "user_{$uid}_profile"; + if(!empty($_G[$var]['department'])){ + $info['department_tree'] = $_G[$var]['department_tree']=C::t('organization')->getPathByOrgid(intval($_G[$var]['department'])); + }else{ + $info['department_tree'] = $_G[$var]['department_tree']=lang('please_select_a_organization_or_department'); + } + if($user = C::t('user')->get_user_by_uid($uid)){ + $info = array_merge($user,$info); + } + $field = DB::fetch_first("select attachextensions,maxattachsize,usesize,addsize,buysize,wins,perm from %t where uid = %d",array('user_field',$uid)); + $info = array_merge($field,$info); + return $info; + } + + public function fetch($uid){ + $data=array('uid'=>$uid); + foreach(DB::fetch_all("select * from %t where uid =%d",array($this->_table,$uid)) as $value) { + $data[$value['fieldid']]=$value['value']; + } + return $data; + } + public function fetch_by_field($uid,$field){ //获取用户某项资料的值 + return DB::result_first("select value from %t where uid=%d and fieldid=%s",array($this->_table,$uid,$field)); + } + public function update($uid,$fieldarr){//插入用户资料 + foreach($fieldarr as $key=>$value){ + if(is_array($value)){ + $setarr=array( 'uid'=>$uid, + 'fieldid'=>$key, + 'value'=>$value['value'], + 'privacy'=>$value['privacy'] + ); + }else{ + $setarr=array( 'uid'=>$uid, + 'fieldid'=>$key, + 'value'=>$value + ); + } + + DB::insert($this->_table,$setarr,0,1); + } + return true; + } + public function update_by_skey($fieldid,$val,$uid = 0){ + if(!$uid)$uid = getglobal('uid'); + if(!DB::update($this->_table,array('value'=>$val),array('uid'=>$uid,'fieldid'=>$fieldid))){ + $setarr=array('uid'=>$uid, + 'fieldid'=>$fieldid, + 'value'=>$val + ); + DB::insert($this->_table,$setarr,0,1); + } + return true; + } + public function fetch_phone($phone){ + return DB::fetch_first("select * from %t where `fieldid` = %s and `value` = %s",array($this->_table,'phone',$phone)); + } + public function fetch_weixinid($weixinid){ + return DB::fetch_first("select * from %t where `fieldid` = %s and `value` = %s",array($this->_table,'weixinid',$weixinid)); + } + public function zupdate($uid,$fieldarr){//插入用户资料 + foreach($fieldarr as $key=>$value){ + $setarr=array('uid'=>$uid, + 'fieldid'=>$key, + 'value'=>$value, + 'privacy'=>$value + ); + DB::insert($this->_table,$setarr,0,1); + } + return true; + } + public function insert($fieldarr){//插入用户资料 + $uid=$fieldarr['uid']; + unset($fieldarr['uid']); + foreach($fieldarr as $key=>$value){ + $setarr=array('uid'=>$uid, + 'fieldid'=>$key, + 'value'=>$value + ); + DB::insert($this->_table,$setarr,0,1); + } + return true; + } + public function fetch_privacy_by_uid($uid){ + $uid = intval($uid); + $privacys = array(); + foreach(DB::fetch_all("select privacy,fieldid from %t where uid = %d",array($this->_table,$uid)) as $val){ + $privacys[$val['fieldid']] = $val['privacy']; + } + return $privacys; + } + public function delete($uid){ + $uid=(array)$uid; + return DB::delete($this->_table,"uid IN (".dimplode($uid).")"); + } + public function delete_by_field($fieldids){ //删除用户资料项 + $fieldids=(array)$fieldids; + return DB::delete($this->_table,"fieldid IN (".dimplode($fieldids).")"); + } + public function delete_by_uid($uids){ //删除用户资料 + $uids=(array)$uids; + return DB::delete($this->_table,"uid IN (".dimplode($uids).")"); + } + public function fetch_all($uids) { + $data = array(); + $uids=(array)$uids; + if(!empty($uids)) { + foreach(DB::fetch_all("select * from %t where uid IN (%n)",array($this->_table,$uids)) as $value) { + $data[$value['uid']][$value['fieldid']]=$value['value']; + $data[$value['uid']]['uid']=$value['uid']; + } + } + return $data; + } + + public function count_by_field($field, $val) { + + return DB::result_first('SELECT COUNT(*) as cnt FROM '.DB::table($this->_table).' WHERE '.DB::field($field, $val)); + } + + public function fetch_all_field_value($field) { + return DB::fetch_all('SELECT DISTINCT(`'.$field.'`) FROM '.DB::table($this->_table), null, $field); + } + + public function fetch_all_will_birthday_by_uid($uids) { + $birthlist = array(); + if(!empty($uids)) { + $uids = explode(',', (string)$uids); + $uids = dimplode(dintval($uids, true)); + list($s_month, $s_day) = explode('-', dgmdate(TIMESTAMP-3600*24*3, 'n-j')); + list($n_month, $n_day) = explode('-', dgmdate(TIMESTAMP, 'n-j')); + list($e_month, $e_day) = explode('-', dgmdate(TIMESTAMP+3600*24*7, 'n-j')); + if($e_month == $s_month) { + $wheresql = "sf.birthmonth='$s_month' AND sf.birthday>='$s_day' AND sf.birthday<='$e_day'"; + } else { + $wheresql = "(sf.birthmonth='$s_month' AND sf.birthday>='$s_day') OR (sf.birthmonth='$e_month' AND sf.birthday<='$e_day' AND sf.birthday>'0')"; + } + $data=array(); + foreach(DB::fetch_all("select sf.*,u.username,u.email from %t sf LEFT JOIN %t u USING(uid) ON sf.uid=u.uid where sf.uid IN (%n) and $wheresql",array($this->_table,'user',$uids)) as $value){ + $data[$value['uid']][$value['fileid']]=$value['value']; + $data[$value['uid']]['username']=$value['username']; + } + foreach($data as $value){ + $value['istoday'] = 0; + if($value['birthmonth'] == $n_month && $value['birthday'] == $n_day) { + $value['istoday'] = 1; + } + $key = sprintf("%02d", $value['birthmonth']).sprintf("%02d", $value['birthday']); + $birthlist[$key][] = $value; + ksort($birthlist); + } + + } + return $birthlist; + } +} diff --git a/core/class/table/table_user_profile_setting.php b/core/class/table/table_user_profile_setting.php new file mode 100644 index 0000000..990a7e9 --- /dev/null +++ b/core/class/table/table_user_profile_setting.php @@ -0,0 +1,69 @@ +_table = 'user_profile_setting'; + $this->_pk = 'fieldid'; + $this->_pre_cache_key = 'user_profile_setting_'; + $this->_cache_ttl = 0; + parent::__construct(); + } + public function delete_by_fieldid($fieldid){ + $this->clear_cache('fields_0'); + $this->clear_cache('fields_1'); + return parent::delete($fieldid); + } + public function insert($data,$return_insert_id = false, $replace = false, $silent = false){ + $this->clear_cache('fields_0'); + $this->clear_cache('fields_1'); + return parent::insert($data,$return_insert_id,$replace,$silent); + } + public function range($start = 0, $limit = 0) { + return DB::fetch_all('SELECT * FROM '.DB::table($this->_table).' ORDER BY available DESC, displayorder'.DB::limit($start, $limit), null, $this->_pk); + } + public function fetch_all_by_available_unchangeable($available, $unchangeable) { + return DB::fetch_all('SELECT * FROM %t WHERE available=%d AND unchangeable=%d ORDER BY displayorder', array($this->_table, $available, $unchangeable), $this->_pk); + } + public function fetch_register_info(){ + return DB::fetch_all("SELECT * FROM %t WHERE `showinregister` = %d AND `available` = %d ORDER BY displayorder",array($this->_table,1,1)); + } + public function fetch_all_by_available($available) { + return DB::fetch_all('SELECT * FROM %t WHERE available=%d ORDER BY displayorder', array($this->_table, $available), $this->_pk); + } + + public function fetch_all_by_available_formtype($available, $formtype) { + return DB::fetch_all('SELECT * FROM %t WHERE available=%d AND formtype=%s', array($this->_table, $available, $formtype), $this->_pk); + } + + public function fetch_all_by_available_required($available, $required) { + return DB::fetch_all('SELECT * FROM %t WHERE available=%d AND required=%d', array($this->_table, $available, $required), $this->_pk); + } + + public function fetch_all_by_available_showinregister($available, $showinregister) { + return DB::fetch_all('SELECT * FROM %t WHERE available=%d AND showinregister=%d', array($this->_table, $available, $showinregister), $this->_pk); + } + public function fetch_all_fields_by_available($available=1){//获取资料设置里的fieldid数组 + if(!$available) $available=0; + $fieldids=array(); + if($available){ + $sql=' and available>0'; + } + foreach(DB::fetch_all("select fieldid from %t where 1 $sql ",array($this->_table)) as $value){ + $fieldids[]=$value['fieldid']; + } + return $fieldids; + } + +} diff --git a/core/class/table/table_user_qqconnect.php b/core/class/table/table_user_qqconnect.php new file mode 100644 index 0000000..e13d13e --- /dev/null +++ b/core/class/table/table_user_qqconnect.php @@ -0,0 +1,35 @@ +_table = 'user_qqconnect'; + $this->_pk = 'openid'; + parent::__construct(); + } + public function fetch_by_openid($openid){ + return DB::fetch_first("select qq.openid,u.* from %t qq LEFT JOIN %t u ON qq.uid=u.uid where qq.openid=%d",array($this->_table,'user',$openid)); + } + public function insert_by_openid($openid,$uid,$uinfo,$unbind=0){ + if(!$openid) return false; + if(!$user=C::t('user')->fetch($uid)) return false; + if(!DB::insert($this->_table,array('openid'=>$openid,'uid'=>$uid,'unbind'=>$unbind,'dateline'=>TIMESTAMP),1,true)){ + return false; + } + //使用qq头像 + /*if($uinfo['figureurl_2'] && !$user['avatarstatus']){ + avatar_by_image($uinfo['figureurl_2'],$uid); + }*/ + } +} +?> diff --git a/core/class/table/table_user_salf.php b/core/class/table/table_user_salf.php new file mode 100644 index 0000000..1c625c1 --- /dev/null +++ b/core/class/table/table_user_salf.php @@ -0,0 +1,47 @@ +_table = 'user_salf'; + $this->_pk = 'uid'; + + parent::__construct(); + + } + + public function fetch_by_tokenid($tokenid){ + + return DB::fetch_first("select * from %t where tokenid = %s",array($this->_table,$tokenid)); + } + + public function fetch_by_keyid($kid){ + + return DB::fetch_first("select * from %t where keyid = %d",array($this->_table,$kid)); + } + + public function update_by_tokenid($tokenid,$setarr){ + + return DB::update($this->_table,$setarr,"tokenid = $tokenid"); + } + + public function update_by_host($host,$arr){ + + if(DB::update($this->_table,$arr,"host = $host")){ + return true; + + }else{ + + return false; + + } + } + public function fetch_sdk_by_tokenid($tokenid){ + + return DB::fetch_first("select * from %t as a left join %t as b on a.keyid = b.key where a.tokendid = %s",array($this->_table,'user_sdk',$tokenid)); + } +} \ No newline at end of file diff --git a/core/class/table/table_user_sdk.php b/core/class/table/table_user_sdk.php new file mode 100644 index 0000000..99f502f --- /dev/null +++ b/core/class/table/table_user_sdk.php @@ -0,0 +1,29 @@ +_table = 'user_sdk'; + $this->_pk = 'key'; + + parent::__construct(); + } + + public function fetch_by_host($host) + { + return DB::fetch_first("select * from %t where `host` = %s",array($this->_table,$host)); + } + public function fetch_salf_by_key($key,$token){ + + return DB::fetch_first("select * from %t as a left join %t as b on a.key = b.keyid where a.key = %s and b.tokenid = %s",array($this->_table,'user_salf',$key,$token)); + } + + public function update_by_host($host,$setarr){ + + return DB::update($this->_table,$setarr,array('host'=>$host)); + } +} \ No newline at end of file diff --git a/core/class/table/table_user_setting.php b/core/class/table/table_user_setting.php new file mode 100644 index 0000000..39cb34c --- /dev/null +++ b/core/class/table/table_user_setting.php @@ -0,0 +1,135 @@ +_table = 'user_setting'; + $this->_pk = 'id'; + $this->_pre_cache_key = 'user_setting_'; + $this->_cache_ttl = 60*60; + parent::__construct(); + + } + + public function insert($skeyarr,$uid = 0){//插入用户设置 + if(!$uid)$uid = getglobal('uid'); + $cachkeys=array(); + foreach($skeyarr as $key=>$value){ + $setarr=array('uid'=>$uid, + 'skey'=>$key, + 'svalue'=>$value + ); + $cachkeys[] = $uid.'_'.$key; + DB::insert($this->_table,$setarr,0,1); + } + //更新缓存 + $this->clear_cache($cachkeys); + $this->clear_cache($uid); + return true; + } + public function update($skeyarr,$uid = 0){//更新用户设置 + if(!$uid) $uid = getglobal('uid'); + $cachkeys=array(); + foreach($skeyarr as $key=>$value){ + $setarr=array('uid'=>$uid, + 'skey'=>$key, + 'svalue'=>$value, + ); + $cachkeys[]=$uid.'_'.$key; + DB::insert($this->_table,$setarr,0,1); + } + //更新缓存 + $this->clear_cache($cachkeys); + $this->clear_cache($uid); + return true; + } + public function update_by_skey($skey,$val,$uid = 0){ + if(!$uid)$uid = getglobal('uid'); + if(!DB::update($this->_table,array('svalue'=>$val),array('uid'=>$uid,'skey'=>$skey))){ + $setarr=array('uid'=>$uid, + 'uid'=>$uid, + 'skey'=>$skey, + 'svalue'=>$val + ); + DB::insert($this->_table,$setarr,0,1); + } + //更新缓存 + $this->clear_cache($uid.'_'.$skey); + $this->clear_cache($uid); + return true; + } + public function insert_by_skey($skey,$val,$uid = 0){ + if(!$uid) $uid = getglobal('uid'); + $setarr = array( + 'uid'=>$uid, + 'skey'=>$skey, + 'svalue'=>$val + ); + parent::insert($setarr,0,1); + //更新缓存 + $this->clear_cache($uid.'_'.$skey); + $this->clear_cache($uid); + return true; + } + public function fetch_by_skey($skey,$uid= 0){ //获取用户某项设置值 + static $vals=array(); + if(!$uid) $uid = getglobal('uid'); + $cachekey=$uid.'_'.$skey;//增加缓存 + if($ret=$this->fetch_cache($cachekey)){ + return $ret; + }else{ + $val=DB::result_first("select svalue from %t where uid=%d and skey=%s",array($this->_table,$uid,$skey)); + $this->store_cache($cachekey,$val); + return $val; + } + + } + public function delete_by_field($skeys,$uid=0){ //删除用户某项设置值 + if(!$uid)$uid = getglobal('uid'); + $skeys=(array)$skeys; + $cachekeys=array(); + foreach($skeys as $skey){ + $cachekeys[]=$uid.'_'.$skey; + } + if($ret= DB::delete($this->_table,"skey IN (".dimplode($skeys).") and uid=".$uid)){ + $this->clear_cache($cachekeys); + $this->clear_cache($uid); + return $ret; + } + return false; + } + public function delete_by_uid($uids){ //删除设置 + $uids=(array)$uids; + $cachekeys=array(); + + foreach(DB::fetch_all("select skey,uid from %t where uid IN (%n)",array($this->_table,$uids)) as $value){ + $cachekeys[]=$value['uid'].'_'.$value['skey']; + } + if($ret= DB::delete($this->_table,"uid IN (".dimplode($uids).")")){ + $this->clear_cache($cachekeys); + $this->clear_cache($uids); + return $ret; + } + return false; + + } + //获取当前用户所有设置项 + public function fetch_all_user_setting($uid = 0){ + if(!$uid) $uid = getglobal('uid'); + $settings = array(); + $cachekey='settings_'.$uid; + if($settings = $this->fetch_cache($cachekey)){ + return $settings; + }else{ + foreach(DB::fetch_all("select * from %t where uid = %d",array($this->_table,$uid)) as $v){ + $settings[$v['skey']] = $v['svalue']; + } + $this->store_cache($cachekey,$settings); + return $settings; + } + } +} \ No newline at end of file diff --git a/core/class/table/table_user_status.php b/core/class/table/table_user_status.php new file mode 100644 index 0000000..fc54d32 --- /dev/null +++ b/core/class/table/table_user_status.php @@ -0,0 +1,109 @@ +_table = 'user_status'; + $this->_pk = 'uid'; + $this->_pre_cache_key = 'user_status_'; + + parent::__construct(); + } + + public function increase($uids, $setarr) { + $uids = array_map('intval', (array)$uids); + $sql = array(); + $allowkey = array('buyercredit', 'sellercredit', 'favtimes', 'sharetimes'); + foreach($setarr as $key => $value) { + if(($value = intval($value)) && in_array($key, $allowkey)) { + $sql[] = "`$key`=`$key`+'$value'"; + } + } + if(!empty($sql)){ + DB::query("UPDATE ".DB::table($this->_table)." SET ".implode(',', $sql)." WHERE uid IN (".dimplode($uids).")", 'UNBUFFERED'); + $this->increase_cache($uids, $setarr); + } + } + + public function count_by_ip($ips) { + return !empty($ips) ? DB::result_first('SELECT COUNT(*) FROM %t WHERE regip IN(%n) OR lastip IN (%n)', array($this->_table, $ips, $ips)) : 0; + } + + public function fetch_all_by_ip($ips, $start, $limit) { + $data = array(); + if(!empty($ips) && $limit) { + $data = DB::fetch_all('SELECT * FROM %t WHERE regip IN(%n) OR lastip IN (%n) LIMIT %d, %d', array($this->_table, $ips, $ips, $start, $limit), 'uid'); + } + return $data; + } + + public function fetch_all_orderby_lastpost($uids, $start, $limit) { + $uids = dintval($uids, true); + if($uids) { + return DB::fetch_all('SELECT * FROM %t WHERE uid IN(%n) ORDER BY lastpost DESC '.DB::limit($start, $limit), array($this->_table, $uids), $this->_pk); + } + return array(); + } + + public function count_by_lastactivity_invisible($timestamp, $invisible = 0) { + $addsql = ''; + if($invisible === 1) { + $addsql = ' AND invisible = 1'; + } elseif($invisible === 2) { + $addsql = ' AND invisible = 0'; + } + return $timestamp ? DB::result_first('SELECT COUNT(*) FROM %t WHERE lastactivity >= %d'.$addsql, array($this->_table, $timestamp)) : 0; + } + + + public function fetch_all_by_lastactivity_invisible($timestamp, $invisible = 0, $start = 0, $limit = 0) { + $data = array(); + if($timestamp) { + $addsql = ''; + if($invisible === 1) { + $addsql = ' AND invisible = 1'; + } elseif($invisible === 2) { + $addsql = ' AND invisible = 0'; + } + $data = DB::fetch_all('SELECT * FROM %t WHERE lastactivity >= %d'.$addsql.' ORDER BY lastactivity DESC'.DB::limit($start, $limit), array($this->_table, $timestamp), $this->_pk); + } + return $data; + } + + public function fetch_all_onlines($uids, $lastactivity, $start = 0, $limit = 0) { + $data = array(); + $uids = dintval($uids, true); + if(!empty($uids)) { + $ppp = ($ppp = getglobal('ppp')) ? $ppp + 30 : 100; + if(count($uids) > $ppp) { + $uids = array_slice($uids, 0, $ppp); + } + $length = $limit ? $limit : $start; + $i = 0; + foreach($this->fetch_all($uids) as $uid => $member) { + if($member['lastactivity'] >= $lastactivity) { + $data[$uid] = $member; + if($length && $i >= $length) { + break; + } + $i++; + } + } + } + return $data; + } +} + +?> diff --git a/core/class/table/table_user_verify.php b/core/class/table/table_user_verify.php new file mode 100644 index 0000000..b856a67 --- /dev/null +++ b/core/class/table/table_user_verify.php @@ -0,0 +1,85 @@ +_table = 'user_verify'; + $this->_pk = 'uid'; + $this->_pre_cache_key = 'user_verify_'; + //$this->_cache_ttl = 0; + parent::__construct(); + } + + public function fetch_all_by_vid($vid, $flag, $uids = array()) { + $parameter = array($this->_table); + if($vid > 0 && $vid < 8) { + $wherearr = array(); + if($uids) { + $wherearr[] = is_array($uids) ? 'uid IN(%n)' : 'uid=%d'; + $parameter[] = $uids; + } + $parameter[] = $flag; + $wherearr[] = "verify{$vid}=%d"; + return DB::fetch_all("SELECT * FROM %t WHERE ".implode(' AND ', $wherearr), $parameter, $this->_pk); + } else { + return array(); + } + } + public function fetch_all_search($uid, $vid, $username = '', $order = 'dateline', $start = 0, $limit = 0, $sort = 'DESC') { + $condition = $this->search_condition($uid, $vid, $username); + $ordersql = !empty($order) ? ' ORDER BY '.$order.' '.$sort : ''; + return DB::fetch_all("SELECT * FROM %t v, %t m $condition[0] $ordersql ".DB::limit($start, $limit), $condition[1], $this->_pk); + + } + + public function count_by_uid($uid) { + return DB::result_first('SELECT COUNT(*) FROM %t WHERE uid=%d', array($this->_table, $uid)); + } + + public function count_by_search($uid, $vid, $username = '') { + $condition = $this->search_condition($uid, $vid, $username); + return DB::result_first('SELECT COUNT(*) FROM %t v, %t m '.$condition[0], $condition[1]); + } + + public function search_condition($uid, $vid, $username) { + $parameter = array($this->_table, 'user'); + $wherearr = array(); + if($uid) { + if(is_array($uid)){ + $parameter[] = $uid; + $wherearr[] = 'v.uid IN (%n)'; + }else{ + $parameter[] = $uid; + $wherearr[] = 'v.uid=%d'; + } + + } + if($vid > 0 && $vid < 8) { + $parameter[] = $vid; + $wherearr[] = 'v.verify%d=1'; + } + if(!empty($username)) { + $parameter[] = '%'.$username.'%'; + $wherearr[] = "m.username LIKE %s"; + } + $wherearr[] = "v.uid=m.uid"; + $wheresql = !empty($wherearr) && is_array($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : ''; + return array($wheresql, $parameter); + + } + +} + +?> \ No newline at end of file diff --git a/core/class/table/table_user_verify_info.php b/core/class/table/table_user_verify_info.php new file mode 100644 index 0000000..5d11a18 --- /dev/null +++ b/core/class/table/table_user_verify_info.php @@ -0,0 +1,112 @@ +_table = 'user_verify_info'; + $this->_pk = 'vid'; + + parent::__construct(); + } + public function fetch_by_uid_verifytype($uid, $verifytype) { + return DB::fetch_first('SELECT * FROM %t WHERE uid=%d AND verifytype=%d', array($this->_table, $uid, $verifytype)); + } + public function fetch_all_search($uid, $vid, $flag = null, $username = '', $starttime = 0, $endtime = 0, $order = 'dateline', $start = 0, $limit = 0, $sort = 'DESC',$orgids=array()) { + $condition = $this->search_condition($uid, $vid, $flag, $username, $starttime, $endtime,$orgids); + + $ordersql = !empty($order) ? ' ORDER BY v.'.$order : ''; + + return DB::fetch_all("SELECT * FROM %t v $condition[0] $ordersql ".DB::limit($start, $limit), $condition[1], $this->_pk); + } + public function group_by_verifytype_count() { + return DB::fetch_all('SELECT verifytype, COUNT(*) AS num FROM %t WHERE flag=0 GROUP BY verifytype', array($this->_table)); + } + + public function delete_by_uid($uid, $verifytype = null) { + if($uid) { + $addsql = ''; + if($verifytype !== null) { + $verifytype = dintval($verifytype, is_array($verifytype) ? true : false); + $addsql = ' AND '.DB::field('verifytype', $verifytype); + } + return DB::query('DELETE FROM %t WHERE '.(is_array($uid) ? 'uid IN(%n)' : 'uid=%d').$addsql, array($this->_table, $uid)); + } + return false; + } + + public function count_by_search($uid, $vid, $flag = null, $username = '', $starttime = 0, $endtime = 0,$orgids=array()) { + $condition = $this->search_condition($uid, $vid, $flag, $username, $starttime, $endtime,$orgids); + return DB::result_first('SELECT COUNT(*) FROM %t v'.$condition[0], $condition[1]); + } + + public function search_condition($uid, $vid, $flag, $username, $starttime, $endtime,$orgids) { + $parameter = array($this->_table); + $wheresql=''; + $wherearr = array(); + if($orgids){ + if($vid==1) { + if(is_array($orgids)){ + $parameter[] = $orgids; + $wherearr[] = 'v.orgid IN (%n)'; + }else{ + $parameter[] = $orgids; + $wherearr[] = 'v.orgid=%d'; + } + }else{ + $parameter[] = 'organization_user'; + $parameter[] = $orgids; + $wheresql=" LEFT JOIN %t o ON o.uid=v.uid and o.orgid IN(%n)"; + $wherearr[] = '!isnull(o.dateline)'; + } + } + if($uid) { + if(is_array($uid)){ + $parameter[] = $uid; + $wherearr[] = 'v.uid IN (%n)'; + }else{ + $parameter[] = $uid; + $wherearr[] = 'v.uid=%d'; + } + } + + if($vid >= 0 && $vid < 8) { + $parameter[] = $vid; + $wherearr[] = 'v.verifytype=%d'; + } + if($flag !== null) { + $parameter[] = $flag; + $wherearr[] = 'v.flag=%d'; + } + if($starttime){ + $parameter[] = $starttime; + $wherearr[] = 'v.dateline>=%d'; + } + if($endtime){ + $parameter[] = $endtime; + $wherearr[] = 'v.dateline<=%d'; + } + if(!empty($username)) { + $parameter[] = '%'.$username.'%'; + $wherearr[] = "v.username LIKE %s"; + } + $wheresql .= !empty($wherearr) && is_array($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : ''; + return array($wheresql, $parameter); + + } + + +} + +?> \ No newline at end of file diff --git a/core/class/table/table_user_wechat.php b/core/class/table/table_user_wechat.php new file mode 100644 index 0000000..480cc8c --- /dev/null +++ b/core/class/table/table_user_wechat.php @@ -0,0 +1,27 @@ +_table = 'user_wechat'; + $this->_pk = 'uid'; + + parent::__construct(); + } + function fetch_by_openid($openid,$appid){ + return DB::fetch_first("select * from %t where openid=%s and appid=%s",array($this->_table,$openid,$appid)); + } +} +?> diff --git a/core/class/table/table_usergroup.php b/core/class/table/table_usergroup.php new file mode 100644 index 0000000..b06132a --- /dev/null +++ b/core/class/table/table_usergroup.php @@ -0,0 +1,138 @@ +_table = 'usergroup'; + $this->_pk = 'groupid'; + + parent::__construct(); + } + + public function fetch_by_credits($credits, $type = 'member') { + if(is_array($credits)) { + $creditsf = intval($credits[0]); + $creditse = intval($credits[1]); + } else { + $creditsf = $creditse = intval($credits); + } + return DB::fetch_first('SELECT grouptitle, groupid FROM %t WHERE '.($type ? DB::field('type', $type).' AND ' : '').'%d>=creditshigher AND %d_table, $creditsf, $creditse)); + } + + public function fetch_all_by_type($type = '', $radminid = null, $allfields = false) { + $parameter = array($this->_table); + $wherearr = array(); + if(!empty($type)) { + $parameter[] = $type; + $wherearr[] = is_array($type) ? 'type IN(%n)' : 'type=%s'; + } + if($radminid !== null) { + $parameter[] = $radminid; + $wherearr[] = 'radminid=%d'; + } + $wheresql = !empty($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : ''; + return DB::fetch_all('SELECT '.($allfields ? '*' : 'groupid, grouptitle').' FROM %t '.$wheresql, $parameter, $this->_pk); + } + + public function update($id, $data, $type = '') { + if(!is_array($data) || !$data || !is_array($data) || !$id) { + return null; + } + $condition = DB::field('groupid', $id); + if($type) { + $condition .= ' AND '.DB::field('type', $type); + } + return DB::update($this->_table, $data, $condition); + } + + public function delete($id, $type = '') { + if(!$id) { + return null; + } + $condition = DB::field('groupid', $id); + if($type) { + $condition .= ' AND '.DB::field('type', $type); + } + return DB::delete($this->_table, $condition); + } + + + public function fetch_all_by_groupid($gid) { + if(!$gid) { + return null; + } + return DB::fetch_all('SELECT groupid FROM %t WHERE groupid IN (%n) AND type=\'special\' AND radminid>0', array($this->_table, $gid), $this->_pk); + } + + public function fetch_all_by_not_groupid($gid) { + return DB::fetch_all('SELECT groupid, type, grouptitle, creditshigher, radminid FROM %t WHERE type=\'member\' AND creditshigher=\'0\' OR (groupid NOT IN (%n) AND radminid<>\'1\' AND type<>\'member\') ORDER BY (creditshigher<>\'0\' || creditslower<>\'0\'), creditslower, groupid', array($this->_table, $gid), $this->_pk); + } + + public function fetch_all_not($gid, $creditnotzero = false) { + return DB::fetch_all('SELECT groupid, radminid, type, grouptitle, creditshigher, creditslower FROM %t WHERE groupid NOT IN (%n) ORDER BY '.($creditnotzero ? "(creditshigher<>'0' || creditslower<>'0'), " : '').'creditshigher, groupid', array($this->_table, $gid), $this->_pk); + } + + public function fetch_new_groupid($fetch = false) { + $sql = 'SELECT groupid, grouptitle FROM '.DB::table($this->_table)." WHERE type='member' AND creditslower>'0' ORDER BY creditslower LIMIT 1"; + if($fetch) { + return DB::fetch_first($sql); + } else { + return DB::result_first($sql); + } + } + public function fetch_all($ids) { + if(!$ids) { + return null; + } + return DB::fetch_all('SELECT * FROM %t WHERE '.DB::field('groupid', $ids).' ORDER BY type, radminid, creditshigher', array($this->_table), $this->_pk); + } + + public function fetch_all_switchable($ids) { + if(!$ids) { + return null; + } + return DB::fetch_all('SELECT * FROM %t WHERE (type=\'special\' AND system<>\'private\' AND radminid=\'0\') OR groupid IN (%n) ORDER BY type, system', array($this->_table, $ids), $this->_pk); + } + + public function range_orderby_credit() { + return DB::fetch_all('SELECT * FROM %t ORDER BY (creditshigher<>\'0\' || creditslower<>\'0\'), creditslower, groupid', array($this->_table), $this->_pk); + } + + public function range_orderby_creditshigher() { + return DB::fetch_all('SELECT * FROM %t ORDER BY creditshigher', array($this->_table), $this->_pk); + } + + public function fetch_all_by_radminid($radminid, $glue = '>', $orderby = 'type'){ + $ordersql = ''; + if($ordersql = DB::order($orderby, 'DESC')) { + $ordersql = ' ORDER BY '.$ordersql; + } + return DB::fetch_all('SELECT * FROM %t WHERE %i', array($this->_table, DB::field('radminid', intval($radminid), $glue) . $ordersql), 'groupid'); + } + + public function fetch_table_struct($result = 'FIELD') { + $datas = array(); + $query = DB::query('DESCRIBE %t', array($this->_table)); + while($data = DB::fetch($query)) { + $datas[$data['Field']] = $result == 'FIELD' ? $data['Field'] : $data; + } + return $datas; + } + + public function buyusergroup_exists() { + return DB::result_first("SELECT COUNT(*) FROM %t WHERE type='special' and system>0", array($this->_table)); + } +} + +?> diff --git a/core/class/table/table_usergroup_field.php b/core/class/table/table_usergroup_field.php new file mode 100644 index 0000000..c6f0e31 --- /dev/null +++ b/core/class/table/table_usergroup_field.php @@ -0,0 +1,30 @@ +_table = 'usergroup_field'; + $this->_pk = 'groupid'; + + parent::__construct(); + } + + public function fetch_all() { + return DB::fetch_all("SELECT * FROM %t where 1", array($this->_table),$this->_pk); + } + +} + +?> diff --git a/core/class/table/table_vote.php b/core/class/table/table_vote.php new file mode 100644 index 0000000..db25fe7 --- /dev/null +++ b/core/class/table/table_vote.php @@ -0,0 +1,62 @@ +_table = 'vote'; + $this->_pk = 'voteid'; + + parent::__construct(); + } + + public function fetch_by_voteid($voteid){ + if(!$data=self::fetch($voteid)) return false; + $data['items']=C::t('vote_item')->fetch_by_voteid($voteid); + return $data; + } + public function fetch_by_id_idtype($id,$idtype){ + $voteid=DB::result_first("select voteid from %t where id=%d and idtype=%s",array($this->_table,$id,$idtype)); + return self::fetch_by_voteid($voteid); + } + public function insert_by_voteid($arr,$itemnew){ + if($voteid=parent::insert($arr,1)){ + C::t('vote_item')->update_by_voteid($voteid,array(),$itemnew); + } + return $voteid; + } + public function update_by_voteid($voteid,$arr,$item,$itemnew){ + C::t('vote_item')->update_by_voteid($voteid,$item,$itemnew); + return parent::update($voteid,$arr); + } + + public function delete_by_voteid($voteids){ + $ret=0; + $voteids=(array)$voteids; + if($ret=parent::delete($voteids)){ + C::t('vote_item')->delete_by_voteid($voteids); + } + + return $ret; + } + public function delete_by_id_idtype($ids,$idtype){ + $ids=(array)$ids; + foreach(DB::fetch_all("select voteid from %t where id IN(%n) and idtype=%s",array('vote',$ids,$idtype)) as $value){ + $voteids[]=$value['voteid']; + } + return self::delete_by_voteid($voteids); + } + +} +?> diff --git a/core/class/table/table_vote_item.php b/core/class/table/table_vote_item.php new file mode 100644 index 0000000..3d7dd5a --- /dev/null +++ b/core/class/table/table_vote_item.php @@ -0,0 +1,119 @@ +_table = 'vote_item'; + $this->_pk = 'itemid'; + + parent::__construct(); + } + + public function fetch_by_voteid($voteid,$type=0){ + $data=array(); + $sql='voteid=%d'; + $param=array($this->_table,$voteid); + if($type){ + $sql.=" and type=%d"; + } + foreach(DB::fetch_all("select * from %t where $sql order by disp",$param) as $value){ + if($value['type'] && $value['aid']){ + $value['img']=(DZZSCRIPT?DZZSCRIPT:'index.php').'?mod=io&op=thumbnail&width=240&height=160&path='.dzzencode('attach::'.$value['aid']); + $value['url']=(DZZSCRIPT?DZZSCRIPT:'index.php').'?mod=io&op=thumbnail&width=240&height=160&original=1&path='.dzzencode('attach::'.$value['aid']); + } + $data['type_'.$value['type']][]=$value; + } + return $data; + } + public function delete_by_itemid($itemid){ + $data=parent::fetch($itemid); + if($data['aid']) C::t('attachment')->delete_by_aid($data['aid']); + return parent::delete($itemid); + } + public function delete_by_voteid($voteids){ + $voteids=(array)$voteids; + $itemids=array(); + $aids=array(); + foreach(DB::fetch_all("select itemid,aid from %t where voteid IN(%n)",array($this->_table,$voteids)) as $value){ + if($value['aid']) $aids[]=$value['aid']; + $itemids[]=$value['itemid']; + } + if($ret=parent::delete($itemids)){ + foreach($aids as $aid){ + C::t('attachment')->delete_by_aid($aid); + } + C::t('vote_item_count')->delete_by_itemid($itemids); + } + return $ret; + } + + public function update_by_voteid($voteid,$item,$itemnew){ + if(!$vote=C::t('vote')->fetch($voteid)) return false; + //删除已有的项目 + $sql='voteid=%d'; + $param=array($this->_table,$voteid); + if($item && ($ids=array_keys($item))){ + $sql.=" and itemid NOT IN(%n)"; + $param[]=$ids; + } + $dels=array(); + foreach(DB::fetch_all("select itemid,aid from %t where $sql",$param) as $value){ + if($value['aid']) C::t('attachment')->delete_by_aid($value['aid']); + $dels[]=$value['itemid']; + } + if(parent::delete($dels)){ + C::t('vote_item_count')->delete_by_itemid($dels); + } + + //更新已有项目 + $addcopyaids=array(); + foreach($item as $key => $value){ + if(empty($value['content']) && !$value['aid']) self::delete_by_itemid($key); + $value['content']=getstr($value['content']); + parent::update($key,$value); + } + + //添加新项目 + $disp=DB::result_first("select max(disp) from %t where voteid=%d",array($this->_table,$voteid)); + + foreach($itemnew as $key =>$value){ + if(empty($value['content']) && !$value['aid']) continue; + $disp++; + $setarr=array('voteid'=>$voteid, + 'content'=>getstr($value['content']), + 'type'=>$value['aid']?2:1, + 'aid'=>intval($value['aid']), + 'disp'=>$disp, + 'number'=>0 + ); + if(parent::insert($setarr,1) && $setarr['aid']){ + C::t('attachment')->addcopy_by_aid($setarr['aid']); + } + } + return true; + } + + + + public function update_number_by_itemid($itemids,$uid){ + $itemids=(array)$itemids; + + if($ret=DB::query(" update %t SET number=number+1 where itemid IN (%n) ",array($this->_table,$itemids))){ + C::t('vote_item_count')->insert_by_itemid($itemids,$uid); + } + return $ret; + } +} +?> diff --git a/core/class/table/table_vote_item_count.php b/core/class/table/table_vote_item_count.php new file mode 100644 index 0000000..88557e2 --- /dev/null +++ b/core/class/table/table_vote_item_count.php @@ -0,0 +1,37 @@ +_table = 'vote_item_count'; + $this->_pk = ''; + + parent::__construct(); + } + + public function insert_by_itemid($itemids,$uid){ + $itemids=(array)$itemids; + $ret=0; + foreach($itemids as $itemid){ + $ret+=parent::insert(array('uid'=>$uid,'itemid'=>$itemid,'dateline'=>TIMESTAMP),0,1); + } + return $ret; + } + public function delete_by_itemid($itemids){ + $itemids=(array)$itemids; + return DB::delete($this->_table,"itemid IN (".dimplode($itemids).")"); + } +} +?> diff --git a/core/class/table/table_wx_app.php b/core/class/table/table_wx_app.php new file mode 100644 index 0000000..86c3a39 --- /dev/null +++ b/core/class/table/table_wx_app.php @@ -0,0 +1,25 @@ +_table = 'wx_app'; + $this->_pk = 'appid'; + + parent::__construct(); + } + +} +?> diff --git a/core/cron/cron_cache_cleanup_week.php b/core/cron/cron_cache_cleanup_week.php new file mode 100644 index 0000000..74371ef --- /dev/null +++ b/core/cron/cron_cache_cleanup_week.php @@ -0,0 +1,50 @@ +delete($value['cachekey']); +} + +function removedir($dirname, $keepdir = FALSE ,$time=0) { + $dirname = str_replace(array( "\n", "\r", '..'), array('', '', ''), $dirname); + + if(!is_dir($dirname)) { + return FALSE; + } + $handle = opendir($dirname); + while(($file = readdir($handle)) !== FALSE) { + if($file != '.' && $file != '..') { + $dir = $dirname . DIRECTORY_SEPARATOR . $file; + $mtime=filemtime($dir); + is_dir($dir) ? removedir($dir) : (((TIMESTAMP-$mtime)>$time)? unlink($dir):''); + } + } + closedir($handle); + return !$keepdir ? (@rmdir($dirname) ? TRUE : FALSE) : TRUE; +} +?> diff --git a/core/cron/cron_clean_copys0_attachment_by_month.php b/core/cron/cron_clean_copys0_attachment_by_month.php new file mode 100644 index 0000000..aa68801 --- /dev/null +++ b/core/cron/cron_clean_copys0_attachment_by_month.php @@ -0,0 +1,21 @@ +delete($value['aid']); + } +} \ No newline at end of file diff --git a/core/cron/cron_clean_notification_month.php b/core/cron/cron_clean_notification_month.php new file mode 100644 index 0000000..3f1a427 --- /dev/null +++ b/core/cron/cron_clean_notification_month.php @@ -0,0 +1,19 @@ +delete_clear(0, 30); +C::t('notification')->delete_clear(1, 30); +C::t('notification')->optimize(); + +?> diff --git a/core/cron/cron_database_backup.php b/core/cron/cron_database_backup.php new file mode 100644 index 0000000..1ca54a9 --- /dev/null +++ b/core/cron/cron_database_backup.php @@ -0,0 +1,227 @@ +version() > '4.1' ? 'Engine' : 'Type'; +$tablepre = $_G['config']['db'][1]['tablepre']; +$dbcharset = $_G['config']['db'][1]['dbcharset']; +$backupdir = C::t('setting')->fetch('backupdir'); +if(!$backupdir) { + $backupdir = random(6); + @mkdir('./data/backup_'.$backupdir, 0777); + C::t('setting')->update('backupdir',$backupdir); +} +$backupdir = 'backup_'.$backupdir; +if(!is_dir('./data/'.$backupdir)) { + mkdir('./data/'.$backupdir, 0777); +} +global $excepttables; +$excepttables=array(); +$filename=date('ymd').'_'.random(8); +DB::query('SET SQL_QUOTE_SHOW_CREATE=0', 'SILENT'); +$tables = arraykeys2(fetchtablelist($tablepre), 'Name'); +$memberexist = array_search(DB::table('user'), $tables); +if($memberexist !== FALSE) { + unset($tables[$memberexist]); + array_unshift($tables, DB::table('user')); +} +$time = dgmdate(TIMESTAMP); +$success=false; +global $complete,$startrow; +$startrow=0; +$volume=0;$tableid = 0;$startfrom = 0; +while(!$success){ + $volume += 1; + $idstring = '# Identify: '.base64_encode("$_G[timestamp],".$_G['setting']['version'].",dzz,multivol,{$volume},{$tablepre},{$dbcharset}")."\n"; + $dumpcharset = str_replace('-', '', $_G['charset']); + $backupfilename = './data/'.$backupdir.'/'.str_replace(array('/', '\\', '.', "'"), '', $filename); + $sqldump = ''; + $startfrom=$startrow; + if(!$tableid && $volume == 1) { + foreach($tables as $table) { + $sqldump .= sqldumptablestruct($table); + } + } + $complete = TRUE; + for(; $complete && $tableid < count($tables) && strlen($sqldump) + 500 < 2048 * 1000; $tableid++) { + $sqldump .= sqldumptable($tables[$tableid], $startfrom, strlen($sqldump)); + if($complete) { + $startfrom = 0; + } + } + + $dumpfile = $backupfilename."-%s".'.sql'; + !$complete && $tableid--; + if(trim($sqldump)) { + $sqldump = "$idstring". + "# \n". + "# DzzOffice Multi-Volume Data Dump Vol.$volume\n". + "# Version: DzzOffice! ".$_G['setting']['version']."\n". + "# Time: $time\n". + "# Type: dzz\n". + "# Table Prefix: $tablepre\n". + "#\n". + "# Dzz! Home: http://www.dzzoffice.com\n". + "# Please visit our website for newest infomation about DzzOffice\n". + "# --------------------------------------------------------\n\n\n". + $sqldump; + $dumpfilename = sprintf($dumpfile, $volume); + @$fp = fopen($dumpfilename, 'wb'); + @flock($fp, 2); + if(@!fwrite($fp, $sqldump)) { + @fclose($fp); + runlog('database_export','database_export_file_invalid',1); + } else { + fclose($fp); + unset($sqldump, $zip, $content); + continue; + } + } else { + $success=true; + C::t('cache')->insert(array( + 'cachekey' => 'db_export', + 'cachevalue' => serialize(array('dateline' => $_G['timestamp'])), + 'dateline' => $_G['timestamp'], + ), false, true); + + } +} +function fetchtablelist($tablepre = '') { + global $db; + $arr = explode('.', $tablepre); + $dbname = $arr[1] ? $arr[0] : ''; + $tablepre = str_replace('_', '\_', $tablepre); + $sqladd = $dbname ? " FROM $dbname LIKE '$arr[1]%'" : "LIKE '$tablepre%'"; + $tables = $table = array(); + $query = DB::query("SHOW TABLE STATUS $sqladd"); + while($table = DB::fetch($query)) { + $table['Name'] = ($dbname ? "$dbname." : '').$table['Name']; + $tables[] = $table; + } + return $tables; +} + +function arraykeys2($array, $key2) { + $return = array(); + foreach($array as $val) { + $return[] = $val[$key2]; + } + return $return; +} + +function sqldumptablestruct($table) { + global $_G, $db, $excepttables; + if(in_array($table, $excepttables)) { + return; + } + $createtable = DB::query("SHOW CREATE TABLE $table", 'SILENT'); + if(!DB::error()) { + $tabledump = "DROP TABLE IF EXISTS $table;\n"; + } else { + return ''; + } + + + $create = $db -> fetch_row($createtable); + + if (strpos($table, '.') !== FALSE) { + $tablename = substr($table, strpos($table, '.') + 1); + $create[1] = str_replace("CREATE TABLE $tablename", 'CREATE TABLE ' . $table, $create[1]); + } + $tabledump .= $create[1]; + $tablestatus = DB::fetch_first("SHOW TABLE STATUS LIKE '$table'"); + $tabledump .= (($tablestatus['Auto_increment'] && (strpos($tabledump,'AUTO_INCREMENT')===false))? " AUTO_INCREMENT=$tablestatus[Auto_increment]" : ''). ";\n\n"; + if ($_GET['sqlcompat'] == 'MYSQL40' && $db -> version() >= '4.1' && $db -> version() < '5.1') { + if ($tablestatus['Auto_increment'] <> '') { + $temppos = strpos($tabledump, ','); + $tabledump = substr($tabledump, 0, $temppos) . ' auto_increment' . substr($tabledump, $temppos); + } + if ($tablestatus['Engine'] == 'MEMORY') { + $tabledump = str_replace('TYPE=MEMORY', 'TYPE=HEAP', $tabledump); + } + } + return $tabledump; +} + +function sqldumptable($table, $startfrom = 0, $currsize = 0) { + global $_G, $startrow, $dumpcharset, $complete, $excepttables; + $db = & DB::object(); + $offset = 300; + $tabledump = ''; + $tablefields = array(); + $_GET['usehex']=TRUE; + $query = DB::query("SHOW FULL COLUMNS FROM $table", 'SILENT'); + if(strexists($table, 'adminsessions')) { + return ; + } elseif(!$query && DB::errno() == 1146) { + return; + } elseif(!$query) { + $_GET['usehex'] = FALSE; + } else { + while($fieldrow = DB::fetch($query)) { + $tablefields[] = $fieldrow; + } + } + + if(!in_array($table, $excepttables)) { + $tabledumped = 0; + $numrows = $offset; + $firstfield = $tablefields[0]; + + while($currsize + strlen($tabledump) + 500 < 2048 * 1000 && $numrows == $offset) { + if($firstfield['Extra'] == 'auto_increment') { + $selectsql = "SELECT * FROM $table WHERE $firstfield[Field] > $startfrom ORDER BY $firstfield[Field] LIMIT $offset"; + } else { + $selectsql = "SELECT * FROM $table LIMIT $startfrom, $offset"; + } + $tabledumped = 1; + $rows = DB::query($selectsql); + $numfields = $db->num_fields($rows); + + $numrows = DB::num_rows($rows); + while($row = $db->fetch_row($rows)) { + $comma = $t = ''; + for($i = 0; $i < $numfields; $i++) { + + $t .= $comma.($_GET['usehex'] && !empty($row[$i]) && (strexists($tablefields[$i]['Type'], 'char') || strexists($tablefields[$i]['Type'], 'text')) ? '0x'.bin2hex($row[$i]) : '\''.mysql_escape_string($row[$i]).'\''); + $comma = ','; + } + + if(strlen($t) + $currsize + strlen($tabledump) + 500 < 2048 * 1000) { + if($firstfield['Extra'] == 'auto_increment') { + $startfrom = $row[0]; + } else { + $startfrom++; + } + $tabledump .= "INSERT INTO $table VALUES ($t);\n"; + + } else { + + $complete = FALSE; + break 2; + } + } + } + $startrow = $startfrom; + $tabledump .= "\n"; + } + return $tabledump; +} + +?> diff --git a/core/cron/cron_fragment_cleanup_day.php b/core/cron/cron_fragment_cleanup_day.php new file mode 100644 index 0000000..8cc6084 --- /dev/null +++ b/core/cron/cron_fragment_cleanup_day.php @@ -0,0 +1,35 @@ +init($arr['bz'],1); + if(is_array($oss) && $oss['error']) continue; + $response=$oss->abort_multipart_upload($arr['bucket'], $arr['object'], $arr['upload_id']); + if($response->isOk()){ + $dkeys[]=$value['cachekey']; + } + }else{ + $dkeys[]=$value['cachekey']; + } +} +if($dkeys) C::t('cache')->delete($dkeys); +?> diff --git a/core/cron/cron_getAtoken_by_Rtoken_week.php b/core/cron/cron_getAtoken_by_Rtoken_week.php new file mode 100644 index 0000000..1ed29c8 --- /dev/null +++ b/core/cron/cron_getAtoken_by_Rtoken_week.php @@ -0,0 +1,34 @@ +getAccessTokenByRefreshToken($value['refresh_token'],$value['scope']) ){ + $token['refreshtime']=TIMESTAMP; + if($token['access_token']) C::t('connect_pan')->update($value['id'],$token); + } + } +} +?> diff --git a/core/cron/cron_imgcache_cleanup_week.php b/core/cron/cron_imgcache_cleanup_week.php new file mode 100644 index 0000000..284af6b --- /dev/null +++ b/core/cron/cron_imgcache_cleanup_week.php @@ -0,0 +1,38 @@ +$time)? unlink($dir):''); + } + } + closedir($handle); + return !$keepdir ? (@rmdir($dirname) ? TRUE : FALSE) : TRUE; +} +?> diff --git a/core/cron/cron_movetospace_attachment.php b/core/cron/cron_movetospace_attachment.php new file mode 100644 index 0000000..6e2264b --- /dev/null +++ b/core/cron/cron_movetospace_attachment.php @@ -0,0 +1,22 @@ +getRemoteId(); +if($remoteid>1){ + foreach(DB::fetch_all("select * from %t where dateline<%d and remote<2 and filesize>0 ORDER BY dateline DESC limit $limit",array('attachment',$delay,$limit)) as $value){ + io_remote::Migrate($value,$remoteid); + } +} \ No newline at end of file diff --git a/core/function/cache/cache_fields_optional.php b/core/function/cache/cache_fields_optional.php new file mode 100644 index 0000000..76e544d --- /dev/null +++ b/core/function/cache/cache_fields_optional.php @@ -0,0 +1,33 @@ +fetch_all_by_available_required(1, 0) as $field) { + $choices = array(); + if($field['selective']) { + foreach(explode("\n", $field['choices']) as $item) { + list($index, $choice) = explode('=', $item); + $choices[trim($index)] = trim($choice); + } + $field['choices'] = $choices; + } else { + unset($field['choices']); + } + $data['field_'.$field['fieldid']] = $field; + } + + savecache('fields_optional', $data); +} + +?> \ No newline at end of file diff --git a/core/function/cache/cache_fields_register.php b/core/function/cache/cache_fields_register.php new file mode 100644 index 0000000..a10b2d2 --- /dev/null +++ b/core/function/cache/cache_fields_register.php @@ -0,0 +1,26 @@ +fetch_all_by_available_showinregister(1, 1) as $field) { + $choices = array(); + if($field['selective']) { + foreach(explode("\n", $field['choices']) as $item) { + list($index, $choice) = explode('=', $item); + $choices[trim($index)] = trim($choice); + } + $field['choices'] = $choices; + } else { + unset($field['choices']); + } + $data['field_'.$field['fieldid']] = $field; + } + savecache('fields_register', $data); +} + +?> \ No newline at end of file diff --git a/core/function/cache/cache_fields_required.php b/core/function/cache/cache_fields_required.php new file mode 100644 index 0000000..9617a6f --- /dev/null +++ b/core/function/cache/cache_fields_required.php @@ -0,0 +1,34 @@ +fetch_all_by_available_required(1, 1) as $field) { + $choices = array(); + if($field['selective']) { + foreach(explode("\n", $field['choices']) as $item) { + list($index, $choice) = explode('=', $item); + $choices[trim($index)] = trim($choice); + } + $field['choices'] = $choices; + } else { + unset($field['choices']); + } + $data['field_'.$field['fieldid']] = $field; + } + + savecache('fields_required', $data); +} + +?> \ No newline at end of file diff --git a/core/function/cache/cache_organization.php b/core/function/cache/cache_organization.php new file mode 100644 index 0000000..db35262 --- /dev/null +++ b/core/function/cache/cache_organization.php @@ -0,0 +1,22 @@ +fetch_uids_by_orgid($value['orgid']);//获取部门所有用户(不包括下级) + $value['moderators']=C::t('organization_admin')->fetch_moderators_by_orgid($value['orgid']); + $data[$value['orgid']]=$value; + }*/ + savecache('organization', $data); +} + +?> diff --git a/core/function/cache/cache_profilesetting.php b/core/function/cache/cache_profilesetting.php new file mode 100644 index 0000000..eccaaf2 --- /dev/null +++ b/core/function/cache/cache_profilesetting.php @@ -0,0 +1,13 @@ +fetch_all_by_available(1); + + savecache('profilesetting', $data); +} + +?> \ No newline at end of file diff --git a/core/function/cache/cache_setting.php b/core/function/cache/cache_setting.php new file mode 100644 index 0000000..347bce3 --- /dev/null +++ b/core/function/cache/cache_setting.php @@ -0,0 +1,135 @@ +fetch_all_not_key($skipkeys) as $setting) { + if($setting['skey'] == 'attachdir') { + $setting['svalue'] = preg_replace("/\.asp|\\0/i", '0', $setting['svalue']); + $setting['svalue'] = str_replace('\\', '/', substr($setting['svalue'], 0, 2) == './' ? DZZ_ROOT.$setting['svalue'] : $setting['svalue']); + $setting['svalue'] .= substr($setting['svalue'], -1, 1) != '/' ? '/' : ''; + } elseif($setting['skey'] == 'attachurl') { + $setting['svalue'] .= substr($setting['svalue'], -1, 1) != '/' ? '/' : ''; + + } elseif(in_array($setting['skey'], $serialized)) { + $setting['svalue'] = @dunserialize($setting['svalue'], $setting['skey']); + if($setting['skey'] == 'search') { + foreach($setting['svalue'] as $key => $val) { + foreach($val as $k => $v) { + $setting['svalue'][$key][$k] = max(0, intval($v)); + } + } + } + } + $_G['setting'][$setting['skey']] = $data[$setting['skey']] = $setting['svalue']; + } + + include_once DZZ_ROOT.'./core/core_version.php'; + $_G['setting']['version'] = $data['version'] = CORE_VERSION; + + $data['sitemessage']['time'] = !empty($data['sitemessage']['time']) ? $data['sitemessage']['time'] * 1000 : 0; + + $data['disallowfloat'] = is_array($data['disallowfloat']) ? implode('|', $data['disallowfloat']) : ''; + + if(!$data['imagelib']) unset($data['imageimpath']); + + $data['iconview']=C::t('iconview')->fetch_all(); + + + $data['seccodedata'] = is_array($data['seccodedata']) ? $data['seccodedata'] : array(); + if($data['seccodedata']['type'] == 2) { + if(extension_loaded('ming')) { + unset($data['seccodedata']['background'], $data['seccodedata']['adulterate'], + $data['seccodedata']['ttf'], $data['seccodedata']['angle'], + $data['seccodedata']['color'], $data['seccodedata']['size'], + $data['seccodedata']['animator']); + } else { + $data['seccodedata']['animator'] = 0; + } + } elseif($data['seccodedata']['type'] == 99) { + $data['seccodedata']['width'] = 50; + $data['seccodedata']['height'] = 34; + } + + $data['watermarktype'] = !empty($data['watermarktype']) ? dunserialize($data['watermarktype']) : array(); + $data['watermarktext'] = !empty($data['watermarktext']) ? dunserialize($data['watermarktext']) : array(); + foreach($data['watermarktype'] as $k => $v) { + if($data['watermarktype'][$k] == 'text' && $data['watermarktext']['text'][$k]) { + if($data['watermarktext']['text'][$k] && strtoupper(CHARSET) != 'UTF-8') { + $data['watermarktext']['text'][$k] = diconv($data['watermarktext']['text'][$k], CHARSET, 'UTF-8', true); + } + $data['watermarktext']['text'][$k] = bin2hex($data['watermarktext']['text'][$k]); + if(file_exists('static/image/seccode/font/en/'.$data['watermarktext']['fontpath'][$k])) { + $data['watermarktext']['fontpath'][$k] = 'static/image/seccode/font/en/'.$data['watermarktext']['fontpath'][$k]; + } elseif(file_exists('static/image/seccode/font/ch/'.$data['watermarktext']['fontpath'][$k])) { + $data['watermarktext']['fontpath'][$k] = 'static/image/seccode/font/ch/'.$data['watermarktext']['fontpath'][$k]; + } else { + $data['watermarktext']['fontpath'][$k] = 'static/image/seccode/font/'.$data['watermarktext']['fontpath'][$k]; + } + $data['watermarktext']['color'][$k] = preg_replace_callback('/#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/', function($matches) { return hexdec($matches[1]).','.hexdec($matches[2]).','.hexdec($matches[3]); }, $data['watermarktext']['color'][$k]); + $data['watermarktext']['shadowcolor'][$k] = preg_replace_callback('/#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/', function($matches) { return hexdec($matches[1]).','.hexdec($matches[2]).','.hexdec($matches[3]); }, $data['watermarktext']['shadowcolor'][$k]); + + + } else { + $data['watermarktext']['text'][$k] = ''; + $data['watermarktext']['fontpath'][$k] = ''; + $data['watermarktext']['color'][$k] = ''; + $data['watermarktext']['shadowcolor'][$k] = ''; + } + } + if(!$data['jspath']) { + $data['jspath'] = 'static/js/'; + } + + + $reginputbwords = array('username', 'password', 'password2', 'email'); + if(in_array($data['reginput']['username'], $reginputbwords) || !preg_match('/^[A-z]\w+?$/', $data['reginput']['username'])) { + $data['reginput']['username'] = random(6); + } + if(in_array($data['reginput']['password'], $reginputbwords) || !preg_match('/^[A-z]\w+?$/', $data['reginput']['password'])) { + $data['reginput']['password'] = random(6); + } + if(in_array($data['reginput']['password2'], $reginputbwords) || !preg_match('/^[A-z]\w+?$/', $data['reginput']['password2'])) { + $data['reginput']['password2'] = random(6); + } + if(in_array($data['reginput']['email'], $reginputbwords) || !preg_match('/^[A-z]\w+?$/', $data['reginput']['email'])) { + $data['reginput']['email'] = random(6); + } + + $data['verhash']=random(3); + + $data['output'] = $output; + + savecache('setting', $data); + $_G['setting'] = $data; +} + +function parsehighlight($highlight) { + if($highlight) { + $colorarray = array('', 'red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'purple', 'gray'); + $string = sprintf('%02d', $highlight); + $stylestr = sprintf('%03b', $string[0]); + + $style = ' style="'; + $style .= $stylestr[0] ? 'font-weight: bold;' : ''; + $style .= $stylestr[1] ? 'font-style: italic;' : ''; + $style .= $stylestr[2] ? 'text-decoration: underline;' : ''; + $style .= $string[1] ? 'color: '.$colorarray[$string[1]] : ''; + $style .= '"'; + } else { + $style = ''; + } + return $style; +} + +?> diff --git a/core/function/cache/cache_smileycodes.php b/core/function/cache/cache_smileycodes.php new file mode 100644 index 0000000..2e66b1c --- /dev/null +++ b/core/function/cache/cache_smileycodes.php @@ -0,0 +1,21 @@ +fetch_all_by_type('smiley', 1) as $type) { + foreach(C::t('smiley')->fetch_all_by_type_code_typeid('smiley', $type['typeid']) as $smiley) { + if($size = @getimagesize('./static/image/smiley/'.$type['directory'].'/'.$smiley['url'])) { + $data[$smiley['id']] = $smiley['code']; + } + } + } + + savecache('smileycodes', $data); +} + +?> \ No newline at end of file diff --git a/core/function/cache/cache_smileytypes.php b/core/function/cache/cache_smileytypes.php new file mode 100644 index 0000000..e7439af --- /dev/null +++ b/core/function/cache/cache_smileytypes.php @@ -0,0 +1,20 @@ +fetch_all_by_type('smiley', 1) as $type) { + $typeid = $type['typeid']; + unset($type['typeid']); + if(C::t('smiley')->count_by_type_code_typeid('smiley', $typeid)) { + $data[$typeid] = $type; + } + } + + savecache('smileytypes', $data); +} + +?> \ No newline at end of file diff --git a/core/function/cache/cache_smilies.php b/core/function/cache/cache_smilies.php new file mode 100644 index 0000000..5e12cdc --- /dev/null +++ b/core/function/cache/cache_smilies.php @@ -0,0 +1,20 @@ + array(), 'replacearray' => array(), 'typearray' => array()); + foreach(C::t('smiley')->fetch_all_cache() as $smiley) { + $data['searcharray'][$smiley['id']] = '/'.preg_quote(dhtmlspecialchars($smiley['code']), '/').'/'; + $data['replacearray'][$smiley['id']] = $smiley['url']; + $data['typearray'][$smiley['id']] = $smiley['typeid']; + } + + savecache('smilies', $data); +} + +?> \ No newline at end of file diff --git a/core/function/cache/cache_smilies_js.php b/core/function/cache/cache_smilies_js.php new file mode 100644 index 0000000..289e8a6 --- /dev/null +++ b/core/function/cache/cache_smilies_js.php @@ -0,0 +1,57 @@ +fetch('fastsmiley', true); + $return_type = 'var smilies_type = new Array();'; + $return_array = 'var smilies_array = new Array();var smilies_fast = new Array();'; + $spp = $_G['setting']['smcols'] * $_G['setting']['smrows']; + $fpre = ''; + foreach(C::t('imagetype')->fetch_all_by_type('smiley', 1) as $type) { + $return_data = array(); + $return_datakey = ''; + $i = 0;$j = 1;$pre = ''; + $return_type .= 'smilies_type[\'_'.$type['typeid'].'\'] = [\''.str_replace('\'', '\\\'', $type['name']).'\', \''.str_replace('\'', '\\\'', $type['directory']).'\'];'; + $return_datakey .= 'smilies_array['.$type['typeid'].'] = new Array();'; + foreach(C::t('smiley')->fetch_all_by_type_code_typeid('smiley', $type['typeid']) as $smiley) { + if($i >= $spp) { + $return_data[$j] = 'smilies_array['.$type['typeid'].']['.$j.'] = ['.$return_data[$j].'];'; + $j++;$i = 0;$pre = ''; + } + if($size = @getimagesize(DZZ_ROOT.'./static/image/smiley/'.$type['directory'].'/'.$smiley['url'])) { + $smiley['code'] = str_replace('\'', '\\\'', $smiley['code']); + $smileyid = $smiley['id']; + $s = smthumb($size, $_G['setting']['smthumb']); + $smiley['w'] = $s['w']; + $smiley['h'] = $s['h']; + $l = smthumb($size); + $smiley['lw'] = $l['w']; + unset($smiley['id'], $smiley['directory']); + $return_data[$j] .= $pre.'[\''.$smileyid.'\', \''.$smiley['code'].'\',\''.str_replace('\'', '\\\'', $smiley['url']).'\',\''.$smiley['w'].'\',\''.$smiley['h'].'\',\''.$smiley['lw'].'\',\''.$smiley['title'].'\']'; + if(is_array($fastsmiley[$type['typeid']]) && in_array($smileyid, $fastsmiley[$type['typeid']])) { + $return_fast .= $fpre.'[\''.$type['typeid'].'\',\''.$j.'\',\''.$i.'\']'; + $fpre = ','; + } + $pre = ','; + } + $i++; + } + $return_data[$j] = 'smilies_array['.$type['typeid'].']['.$j.'] = ['.$return_data[$j].'];'; + $return_array .= $return_datakey.implode('', $return_data); + } + $cachedir = DZZ_ROOT.'./data/cache/'; + if(@$fp = fopen($cachedir.'smilies_var.js', 'w')) { + fwrite($fp, 'var smthumb = \''.$_G['setting']['smthumb'].'\';'.$return_type.$return_array.'var smilies_fast=['.$return_fast.'];'); + fclose($fp); + } else { + exit('Can not write to cache files, please check directory ./data/ and ./data/cache/ .'); + } + +} + +?> \ No newline at end of file diff --git a/core/function/cache/cache_usergroups.php b/core/function/cache/cache_usergroups.php new file mode 100644 index 0000000..62df322 --- /dev/null +++ b/core/function/cache/cache_usergroups.php @@ -0,0 +1,44 @@ +fetch_all(); + foreach(C::t('usergroup')->range_orderby_creditshigher() as $key=>$value) { + $group = array_merge(array('groupid' => $value['groupid'], 'type' => $value['type'], 'grouptitle' => $value['grouptitle'], 'creditshigher' => $value['creditshigher'], 'creditslower' => $value['creditslower'], 'stars' => $value['stars'], 'color' => $value['color'], 'icon' => $value['icon'], 'system' => $value['system']), $data_uf[$key]); + + $groupid = $group['groupid']; + $group['grouptitle'] = $group['color'] ? ''.$group['grouptitle'].'' : $group['grouptitle']; + unset($group['creditshigher'], $group['creditslower']); + unset($group['groupid']); + $data[$groupid] = $group; + } + savecache('usergroups', $data); + + build_cache_usergroups_single(); + + +} + +function build_cache_usergroups_single() { + $data_uf = C::t('usergroup_field')->fetch_all(); + foreach(C::t('usergroup')->range() as $gid => $data) { + $data = array_merge($data, (array)$data_uf[$gid]); + $ratearray = array(); + if($data['raterange']) { + foreach(explode("\n", $data['raterange']) as $rating) { + $rating = explode("\t", $rating); + $ratearray[$rating[0]] = array('isself' => $rating[1], 'min' => $rating[2], 'max' => $rating[3], 'mrpd' => $rating[4]); + } + } + $data['raterange'] = $ratearray; + $data['grouptitle'] = $data['color'] ? ''.$data['grouptitle'].'' : $data['grouptitle']; + $data['grouptype'] = $data['type']; + $data['grouppublic'] = $data['system'] != 'private'; + $data['maxspacesize'] = intval($data['maxspacesize']); + unset($data['type'], $data['system'], $data['creditshigher'], $data['creditslower'], $data['groupavatar'], $data['admingid']); + savecache('usergroup_'.$data['groupid'], $data); + } +} diff --git a/core/function/cache/cache_userstats.php b/core/function/cache/cache_userstats.php new file mode 100644 index 0000000..0944ce5 --- /dev/null +++ b/core/function/cache/cache_userstats.php @@ -0,0 +1,16 @@ +count(); + $member = C::t('user')->range(0, 1, 'DESC'); + $member = current($member); + $newsetuser = $member['username']; + $data = array('totalmembers' => $totalmembers, 'newsetuser' => $newsetuser); + savecache('userstats', $data); +} + +?> \ No newline at end of file diff --git a/core/function/function_cache.php b/core/function/function_cache.php new file mode 100644 index 0000000..994bb09 --- /dev/null +++ b/core/function/function_cache.php @@ -0,0 +1,162 @@ +read()) { + + if(!in_array($entry, array('.', '..')) && preg_match("/^cache\_([\_\w]+)\.php$/", $entry, $entryr) && $entryr[1] != 'setting' && substr($entry, -4) == '.php' && is_file($cachedir.'/'.$entry)) { + @include_once libfile('cache/'.$entryr[1], 'function'); + call_user_func('build_cache_'.$entryr[1]); + } + } + + //处理应用的缓存 + foreach(C::t('app_market')->fetch_all_identifier(1) as $value) { + if(empty($value['app_path'])) $value['app_path']='dzz'; + $appdir=$value['app_path']; + $dir=$value['identifier']; + $cachedir = DZZ_ROOT.'./'.$appdir.'/'.$dir.'/cache'; + if(is_dir($cachedir)) { + $cachedirhandle = dir($cachedir); + while($entry = $cachedirhandle->read()) { + if(!in_array($entry, array('.', '..')) && preg_match("/^cache\_([\_\w]+)\.php$/", $entry, $entryr) && substr($entry, -4) == '.php' && is_file($cachedir.'/'.$entry)) { + try{ + @include_once $cachedir.'/'.$entry; + //call_user_func('build_cache_'.$dir.'_'.$entryr[1]); + if(function_exists('build_cache_'.$appdir.'_'.$dir.'_'.$entryr[1])) call_user_func('build_cache_'.$appdir.'_'.$dir.'_'.$entryr[1]); + elseif(function_exists('build_cache_'.$dir.'_'.$entryr[1])) call_user_func('build_cache_'.$dir.'_'.$entryr[1]); + elseif(function_exists('build_cache_app_'.$entryr[1])) call_user_func('build_cache_app_'.$entryr[1]);; + }catch(Exception $e){continue;} + } + } + } + } + } else { + + foreach($updatelist as $entry) { + $entrys = explode(':', $entry); + + if(count($entrys) == 1) {//核心缓存 + @include_once libfile('cache/'.$entry, 'function'); + call_user_func('build_cache_'.$entry); + }elseif(count($entrys)==2){//兼容原先默认dzz目录的情况,dzz目录内的可以忽略app_path; + try{ + @include_once DZZ_ROOT.'./dzz/'.$entrys[0].'/cache/cache_'.$entrys[1].'.php'; + if(function_exists('build_cache_'.$entrys[0].'_'.$entrys[1])) call_user_func('build_cache_'.$entrys[0].'_'.$entrys[1]); + elseif(function_exists('build_cache_app_'.$entryr[1])) call_user_func('build_cache_app_'.$entrys[1]); + }catch(Exception $e){continue;} + }elseif(count($entrys)==3){ + try{ + @include_once DZZ_ROOT.'./'.$entrys[0].'/'.$entrys[1].'/cache/cache_'.$entrys[2].'.php'; + if(function_exists('build_cache_'.$entrys[1].'_'.$entrys[2])) call_user_func('build_cache_'.$entrys[1].'_'.$entrys[2]); + elseif(function_exists('build_cache_app_'.$entryr[1])) call_user_func('build_cache_app_'.$entrys[1]); + }catch(Exception $e){continue;} + } else {//插件缓存 + + } + } + } + +} +function writetocache($script, $cachedata, $prefix = 'cache_') { + global $_G; + + $dir = DZZ_ROOT.'./data/sysdata/'; + if(!is_dir($dir)) { + dmkdir($dir, 0777); + } + if($fp = @fopen("$dir$prefix$script.php", 'wb')) { + fwrite($fp, ""); + fclose($fp); + } else { + exit('Can not write to cache files, please check directory ./data/ and ./data/sysdata/ .'); + } +} +function getcachevars($data, $type = 'VAR') { + $evaluate = ''; + foreach($data as $key => $val) { + if(!preg_match("/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/", $key)) { + continue; + } + if(is_array($val)) { + $evaluate .= "\$$key = ".arrayeval($val).";\n"; + } else { + $val = addcslashes($val, '\'\\'); + $evaluate .= $type == 'VAR' ? "\$$key = '$val';\n" : "define('".strtoupper($key)."', '$val');\n"; + } + } + return $evaluate; +} +function smthumb($size, $smthumb = 50) { + if($size[0] <= $smthumb && $size[1] <= $smthumb) { + return array('w' => $size[0], 'h' => $size[1]); + } + $sm = array(); + $x_ratio = $smthumb / $size[0]; + $y_ratio = $smthumb / $size[1]; + if(($x_ratio * $size[1]) < $smthumb) { + $sm['h'] = ceil($x_ratio * $size[1]); + $sm['w'] = $smthumb; + } else { + $sm['w'] = ceil($y_ratio * $size[0]); + $sm['h'] = $smthumb; + } + return $sm; +} + + +function arrayeval($array, $level = 0) { + if(!is_array($array)) { + return "'".$array."'"; + } + if(is_array($array) && function_exists('var_export')) { + return var_export($array, true); + } + + $space = ''; + for($i = 0; $i <= $level; $i++) { + $space .= "\t"; + } + $evaluate = "Array\n$space(\n"; + $comma = $space; + if(is_array($array)) { + foreach($array as $key => $val) { + $key = is_string($key) ? '\''.addcslashes($key, '\'\\').'\'' : $key; + $val = !is_array($val) && (!preg_match("/^\-?[1-9]\d*$/", $val) || strlen($val) > 12) ? '\''.addcslashes($val, '\'\\').'\'' : $val; + if(is_array($val)) { + $evaluate .= "$comma$key => ".arrayeval($val, $level + 1); + } else { + $evaluate .= "$comma$key => $val"; + } + $comma = ",\n$space"; + } + } + $evaluate .= "\n$space)"; + return $evaluate; +} +function cleartemplatecache() { + clearHooksCache(); + $tpl = dir(DZZ_ROOT.'./data/template'); + while($entry = $tpl->read()) { + if(preg_match("/(\.tpl\.php|\.js)$/", $entry)) { + @unlink(DZZ_ROOT.'./data/template/'.$entry); + } + } + $tpl->close(); +} +function clearHooksCache(){ + @unlink(DZZ_ROOT.'./data/cache/tags.php'); +} + +?> diff --git a/core/function/function_code.php b/core/function/function_code.php new file mode 100644 index 0000000..d38bd85 --- /dev/null +++ b/core/function/function_code.php @@ -0,0 +1,527 @@ +]*?>(.*?)<\/script>/i", '', $message); + } + + if($allowat) { + if(strpos($msglower, '[/uid]') !== FALSE) { + //$message = preg_replace("/\[uid=(\d+)\](.+?)\[\/uid\]/ies", "parseat('\\1', '\\2' ,'uid')", $message); + $message = preg_replace_callback("/\[uid=(\d+)\](.+?)\[\/uid\]/is", function($matches){ return parseat($matches[1], $matches[2],'uid'); }, $message); + } + if(strpos($msglower, '[/org]') !== FALSE) { + //$message = preg_replace("/\[org=(\d+)\](.+?)\[\/org\]/ies", "parseat('\\1', '\\2','gid')", $message); + $message = preg_replace_callback("/\[org=(\d+)\](.+?)\[\/org\]/is", function($matches){ return parseat($matches[1], $matches[2],'uid'); }, $message); + } + } + if($allowsmilies) { + $message = parsesmiles($message); + } + + /*if($allowbbcode) { + if(strpos($msglower, 'ed2k://') !== FALSE) { + $message = preg_replace("/ed2k:\/\/(.+?)\//e", "parseed2k('\\1')", $message); + } + }*/ + + if($allowbbcode) { + if(strpos($msglower, '[/url]') !== FALSE) { + //$message = preg_replace("/\[url(=((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.|mailto:)?([^\r\n\[\"']+?))?\](.+?)\[\/url\]/ies", "parseurl('\\1', '\\5', '\\2')", $message); + $message = preg_replace_callback("/\[url(=((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.|mailto:)?([^\r\n\[\"']+?))?\](.+?)\[\/url\]/is", function($matches) { return parseurl($matches[1], $matches[5], $matches[2]); }, $message); + + + } + if(strpos($msglower, '[/email]') !== FALSE) { + //$message = preg_replace("/\[email(=([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+))?\](.+?)\[\/email\]/ies", "parseemail('\\1', '\\4')", $message); + $message = preg_replace_callback("/\[email(=([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+))?\](.+?)\[\/email\]/is", function($matches) { return parseemail($matches[1], $matches[4]); }, $message); + + } + + $nest = 0; + while(strpos($msglower, '[table') !== FALSE && strpos($msglower, '[/table]') !== FALSE){ + //$message = preg_replace("/\[table(?:=(\d{1,4}%?)(?:,([\(\)%,#\w ]+))?)?\]\s*(.+?)\s*\[\/table\]/ies", "parsetable('\\1', '\\2', '\\3')", $message); + $message = preg_replace_callback("/\[table(?:=(\d{1,4}%?)(?:,([\(\)%,#\w ]+))?)?\]\s*(.+?)\s*\[\/table\]/is", function($matches) { return parsetable($matches[1], $matches[2], $matches[3]); }, $message); + + if(++$nest > 4) break; + } + //修复UBB标签不闭合造成的问题,理论上所有标签都可以以此方法处理 + $message=preg_replace(array( + "/\[u\](.+?)\[\/u\]/i", + "/\[b\](.+?)\[\/b\]/i", + "/\[s\](.+?)\[\/s\]/i", + "/\[i\](.+?)\[\/i\]/i" + ), + array( + "[uu]\\1[/uu]", + "[bb]\\1[/bb]", + "[ss]\\1[/ss]", + "[ii]\\1[/ii]", + ),$message); + + $message = str_replace(array( + '[/color]', '[/backcolor]', '[/size]', '[/font]', '[/align]', '[bb]', '[/bb]', '[ss]', '[/ss]', '[hr]', '[/p]', + '[i=s]', '[ii]', '[/ii]', '[uu]', '[/uu]', '[list]', '[list=1]', '[list=a]', + '[list=A]', "\r\n[*]", '[*]', '[/list]', '[indent]', '[/indent]', '[/float]' + ), array( + '', '', '', '', '', '', '', '', '', '
', '

', '', '', + '', '', '', '