|
|
- <?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" );
- }
- ?>
复制代码
|
|