2核1G3M服务器88一季度

腾讯云,阿里云百度云等 折扣价→点我←

百度云网盘 0.2用户组权限 base.class.php discuz 教程

公共账号 管理员组

<?php

class plugin_baidu_yun_base
{

    public function getEnCodeUrl( $http )
    {
        $http = base64_encode( authcode( $http, "ENCODE" ) );
        $http = "plugin.php?id=baidu_yun:get&url=".$http;
        return $http;
    }

    public function my_deleteattach( )
    {
        $aids = $_GET['aids'];
        if ( empty( $aids ) )
        {
            return;
        }
        foreach ( $aids as $k => $v )
        {
            $v = addslashes( $v );
            $table = $this->get_table_name( $v );
            DB::query( "delete from ".$table." where aid=".$v );
        }
    }

    public function post_edit( )
    {
        if ( isset( $_POST['attachipdate'] ) )
        {
            $this->post_edit_update( );
        }
    }

    public function post_edit_update( )
    {
        $tid = addslashes( $_POST['tid'] );
        $updates = $_POST['attachipdate'];
        foreach ( $updates as $k => $v )
        {
            $k = addslashes( $k );
            $this->delete_the_attachment( $k );
        }
    }

    public function get_attachment_id( $aid )
    {
        $ret = C::t( "forum_attachment" )->fetch( $aid );
        if ( empty( $ret ) )
        {
            return 0;
        }
        return $ret['tid'];
    }

    public function get_store_attachment( $tid, $aid )
    {
        $tid = $this->get_attachment_id( $aid );
        $sql = "select * from ".DB::table( "forum_attachment_".substr( $tid, -1 ) );
        $sql = $sql." where aid=".$aid;
        $attachment = DB::fetch_first( $sql );
        if ( !empty( $attachment ) )
        {
            $this->save_to_baidu_yun( $attachment, FALSE );
        }
    }

    public function delete_the_attachment( $aid )
    {
        $table = $this->get_table_name( $aid );
        DB::query( "delete from ".$table." where aid=".$aid );
    }

    public function save_to_baidu_yun( $attachment, $check = TRUE )
    {
        if ( $check )
        {
            $is_saved = $this->has_stored( $attachment['aid'] );
            if ( $is_saved )
            {
                return $is_saved;
            }
        }
        if ( !isset( $attachment['url'] ) )
        {
            $attach = C::t( "common_setting" )->fetch( "attachurl" )."/forum/";
            $attachment['url'] = $attach;
        }
        $data = array( );
        $data['aid'] = $attachment['aid'];
        $data['is_ok'] = 0;
        $data['tid'] = $attachment['tid'];
        $data['path'] = $attachment['url'].$attachment['attachment'];
        $data['path'] = $data['path']."|fs_".$attachment['aid']."_".$attachment['filename'];
        $table = $this->get_table_name( $attachment['aid'], FALSE );
        DB::insert( $table, $data, TRUE );
        return TRUE;
    }

    public function get_attachment( $aid )
    {
        $sql = "select path from ".$this->get_table_name( $aid )." where aid=".$aid." and is_ok = 1";
        $ret = DB::fetch_first( $sql );
        if ( empty( $ret ) )
        {
            return;
        }
        return $ret['path'];
    }

    public function get_the_store_attachment( $aid )
    {
        $sql = "select is_ok,path from ".$this->get_table_name( $aid )." where aid=".$aid;
        $ret = DB::fetch_first( $sql );
        if ( empty( $ret ) )
        {
            return;
        }
        return $ret;
    }

    public function has_stored( $aid )
    {
        $sql = "select id from ".$this->get_table_name( $aid )." where aid=".$aid;
        $ret = DB::fetch_first( $sql );
        if ( !$ret )
        {
            return FALSE;
        }
        return TRUE;
    }

    public function get_table_name( $aid, $pre = TRUE )
    {
        $aid = intval( $aid );
        if ( $pre )
        {
            return DB::table( "baidu_yun_attachment_".substr( $aid, -1 ) );
        }
        return "baidu_yun_attachment_".substr( $aid, -1 );
    }

    public function get_http_url( $path, $access_token )
    {
        if ( CHARSET != "utf-8" )
        {
            $path = mb_convert_encoding( $path, "utf-8", CHARSET );
        }
        $http = "https://pcs.baidu.com/rest/2.0/pcs/file?method=download";
        $http = $http."&path=".urlencode( $path );
        $http = $http."&access_token=".$access_token;
        return $this->getEnCodeUrl( $http );
    }

    public function my_parse_attach( $message )
    {
        preg_match_all( "~zoomfile=\"(.*?)\"~", $message, $attach );
        if ( isset( $attach[1], $attach[1] ) )
        {
            return $message;
        }
        preg_match_all( "~aid=\"(\\d+)\"~", $message, $aid );
        if ( empty( $aid[1] ) )
        {
            return $message;
        }
        foreach ( $attach[1] as $k => $v )
        {
            $id = $aid[1][$k];
            $table = "baidu_yun_attachment_".substr( $id, -1 );
            $sql = "select path,is_ok from ".DB::table( $table )." where aid=".$id;
            $rs = DB::fetch_first( $sql );
            if ( empty( $rs ) || !$rs['is_ok'] )
            {
            }
            else
            {
                $replace = $this->get_http_url( BAIDU_YUN_PATH.$rs['path'], BAIDU_YUN_TOKEN );
                $message = str_replace( $v, $replace, $message );
            }
        }
        return $message;
    }

    public function get_unused_attachment( $aid )
    {
        $attachment = C::t( "forum_attachment_unused" )->fetch( $aid );
        return $attachment;
    }

}

if ( !defined( "IN_DISCUZ" ) )
{
    exit( "Access Denied" );
}
?>


站长窝论坛版权声明 1、本帖标题:百度云网盘 0.2用户组权限 base.class.php
2、论坛网址:站长窝论坛
3、站长窝论坛的资源部分来源于网络,如有侵权,请联系站长进行删除处理。
4、会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。
5、站长窝论坛一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
6、本帖由公共账号在站长窝论坛《程序综合区》版块原创发布, 转载请注明出处!
评论
最新回复 (0)
返回
发新帖