blobstreaming.lib.php
来自「phpMyAdmin图形界面化操作,我已经配置好了,只要把解要压缩后的文件放到站」· PHP 代码 · 共 730 行 · 第 1/2 页
PHP
730 行
<?php/* vim: set expandtab sw=4 ts=4 sts=4: *//** * @author Raj Kissu Rajandran * @version 1.0 * @package BLOBStreaming *//** * checks whether the necessary plugins for BLOBStreaming exist * * @access public * @uses PMA_Config::get() * @uses PMA_Config::settings() * @uses PMA_Config::set() * @uses PMA_PluginsExist() * @uses PMA_BS_SetVariables() * @uses PMA_BS_GetVariables() * @uses PMA_BS_SetFieldReferences() * @return boolean*/function checkBLOBStreamingPlugins(){ // load PMA configuration $PMA_Config = $_SESSION['PMA_Config']; // return if unable to load PMA configuration if (empty($PMA_Config)) return FALSE; // retrieve current server configuration $serverCfg = $PMA_Config->get('Servers'); $serverCfg = $serverCfg[$GLOBALS['server']]; // return if unable to retrieve current server configuration if (! $serverCfg) return FALSE; // if PHP extension in use is 'mysql', specify element 'PersistentConnections' if ($serverCfg['extension'] == "mysql") $serverCfg['PersistentConnections'] = $PMA_Config->settings['PersistentConnections']; // if connection type is TCP, unload socket variable if (strtolower($serverCfg['connect_type']) == "tcp") $serverCfg['socket'] = ""; // define BS Plugin variables $allPluginsExist = TRUE; $PMA_Config->set('PBXT_NAME', 'pbxt'); $PMA_Config->set('PBMS_NAME', 'pbms'); $plugins[$PMA_Config->get('PBXT_NAME')]['Library'] = 'libpbxt.so'; $plugins[$PMA_Config->get('PBXT_NAME')]['Exists'] = FALSE; $plugins[$PMA_Config->get('PBMS_NAME')]['Library'] = 'libpbms.so'; $plugins[$PMA_Config->get('PBMS_NAME')]['Exists'] = FALSE; // retrieve state of BS plugins PMA_PluginsExist($plugins); foreach ($plugins as $plugin_key=>$plugin) if (!$plugin['Exists']) { $allPluginsExist = FALSE; break; } // end if (!$plugin['Exists']) // set variable indicating BS plugin existance $PMA_Config->set('BLOBSTREAMING_PLUGINS_EXIST', $allPluginsExist); // do the plugins exist? if ($allPluginsExist) { // retrieve BS variables from PMA configuration $bs_set_variables = array(); $bs_set_variables[$PMA_Config->get('PBMS_NAME') . '_garbage_threshold'] = (isset($serverCfg['bs_garbage_threshold'])) ? $server['bs_garbage_threshold'] : NULL; $bs_set_variables[$PMA_Config->get('PBMS_NAME') . '_repository_threshold'] = (isset($serverCfg['bs_repository_threshold'])) ? $server['bs_repository_threshold'] : NULL; $bs_set_variables[$PMA_Config->get('PBMS_NAME') . '_temp_blob_timeout'] = (isset($serverCfg['bs_temp_blob_timeout'])) ? $server['bs_temp_blob_timeout'] : NULL; $bs_set_variables[$PMA_Config->get('PBMS_NAME') . '_temp_log_threshold'] = (isset($serverCfg['bs_temp_log_threshold'])) ? $server['bs_temp_log_threshold'] : NULL; // set BS variables to PMA configuration defaults PMA_BS_SetVariables($bs_set_variables); // retrieve updated BS variables (configurable and unconfigurable) $bs_variables = PMA_BS_GetVariables(); // if no BS variables exist, set plugin existance to false and return if (count($bs_variables) <= 0) { $PMA_Config->set('BLOBSTREAMING_PLUGINS_EXIST', FALSE); return FALSE; } // end if (count($bs_variables) <= 0) // switch on BS field references if (strtolower($bs_variables[$PMA_Config->get('PBMS_NAME') . '_field_references']) == "off") if(!PMA_BS_SetFieldReferences('ON')) return FALSE; // get BS server port $BS_PORT = $bs_variables[$PMA_Config->get('PBMS_NAME') . '_port']; // if no BS server port exists, set plugin existance to false and return if (!$BS_PORT) { $PMA_Config->set('BLOBSTREAMING_PLUGINS_EXIST', FALSE); return FALSE; } // end if (!$BS_PORT) // add selected BS, CURL and fileinfo library variables to PMA configuration $PMA_Config->set('BLOBSTREAMING_PORT', $BS_PORT); $PMA_Config->set('BLOBSTREAMING_HOST', $serverCfg['host']); $PMA_Config->set('BLOBSTREAMING_SERVER', $serverCfg['host'] . ':' . $BS_PORT); $PMA_Config->set('CURL_EXISTS', FALSE); $PMA_Config->set('FILEINFO_EXISTS', FALSE); // check if CURL exists if (function_exists("curl_init")) { // initialize curl handler $curlHnd = curl_init(); // CURL exists, set necessary variable and close resource if (!empty($curlHnd)) { $PMA_Config->set('CURL_EXISTS', TRUE); curl_close($curlHnd); } // end if (!empty($curlHnd)) } // end if (function_exists("curl_init")) // check if PECL's fileinfo library exist $finfo = NULL; if (function_exists("finfo_open")) $finfo = finfo_open(FILEINFO_MIME); // fileinfo library exists, set necessary variable and close resource if (!empty($finfo)) { $PMA_Config->set('FILEINFO_EXISTS', TRUE); finfo_close($finfo); } // end if (!empty($finfo)) } // end if ($allPluginsExist) else return FALSE; $bs_tables = array(); // specify table structure for BS reference table $bs_tables[$PMA_Config->get('PBMS_NAME') . '_reference'] = array(); $bs_tables[$PMA_Config->get('PBMS_NAME') . '_reference']['struct'] = <<<EOD CREATE TABLE {$PMA_Config->get('PBMS_NAME')}_reference ( Table_name CHAR(64) COMMENT 'The name of the referencing table', Blob_id BIGINT COMMENT 'The BLOB reference number - part of the BLOB URL', Column_name CHAR(64) COMMENT 'The column name of the referencing field', Row_condition VARCHAR(255) COMMENT 'This condition identifies the row in the table', Blob_url VARCHAR(200) COMMENT 'The BLOB URL for HTTP GET access', Repository_id INT COMMENT 'The repository file number of the BLOB', Repo_blob_offset BIGINT COMMENT 'The offset in the repository file', Blob_size BIGINT COMMENT 'The size of the BLOB in bytes', Deletion_time TIMESTAMP COMMENT 'The time the BLOB was deleted', Remove_in INT COMMENT 'The number of seconds before the reference/BLOB is removed perminently', Temp_log_id INT COMMENT 'Temporary log number of the referencing deletion entry', Temp_log_offset BIGINT COMMENT 'Temporary log offset of the referencing deletion entry' ) ENGINE=PBMS;EOD; // specify table structure for BS repository table $bs_tables[$PMA_Config->get('PBMS_NAME') . '_repository'] = array(); $bs_tables[$PMA_Config->get('PBMS_NAME') . '_repository']['struct'] = <<<EOD CREATE TABLE {$PMA_Config->get('PBMS_NAME')}_repository ( Repository_id INT COMMENT 'The repository file number', Repo_blob_offset BIGINT COMMENT 'The offset of the BLOB in the repository file', Blob_size BIGINT COMMENT 'The size of the BLOB in bytes', Head_size SMALLINT UNSIGNED COMMENT 'The size of the BLOB header - proceeds the BLOB data', Access_code INT COMMENT 'The 4-byte authorisation code required to access the BLOB - part of the BLOB URL', Creation_time TIMESTAMP COMMENT 'The time the BLOB was created', Last_ref_time TIMESTAMP COMMENT 'The last time the BLOB was referenced', Last_access_time TIMESTAMP COMMENT 'The last time the BLOB was accessed (read)', Content_type CHAR(128) COMMENT 'The content type of the BLOB - returned by HTTP GET calls', Blob_data LONGBLOB COMMENT 'The data of this BLOB' ) ENGINE=PBMS;EOD; // specify table structure for BS custom content type table $bs_tables[$PMA_Config->get('PBMS_NAME') . '_custom_content_type'] = array(); $bs_tables[$PMA_Config->get('PBMS_NAME') . '_custom_content_type']['struct'] = <<<EOD CREATE TABLE {$PMA_Config->get('PBMS_NAME')}_custom_content_type ( Blob_url VARCHAR(200) COMMENT 'The BLOB URL for HTTP GET access', Content_type VARCHAR(255) COMMENT 'The custom MIME type for a given BLOB reference as specified by the user', PRIMARY KEY(Blob_url) );EOD; // add BS tables to PMA configuration $PMA_Config->set('BLOBSTREAMING_TABLES', $bs_tables); return TRUE;}/** * checks for databases that support BLOBStreaming * * @access public * @uses PMA_GetDatabases() * @uses PMA_TablesExist() * @uses PMA_Config::set()*/function checkBLOBStreamableDatabases(){ // load PMA configuration $PMA_Config = $_SESSION['PMA_Config']; // return if unable to load PMA configuration if (empty($PMA_Config)) return; // retrieve BS tables from PMA configuration $session_bs_tables = $PMA_Config->get('BLOBSTREAMING_TABLES'); $bs_databases = array(); $bs_tables = array(); // return if BS tables do not exist if (!$session_bs_tables) return; foreach ($session_bs_tables as $table_key=>$table) { $bs_tables[$table_key] = array(); $bs_tables[$table_key]['Exists'] = FALSE; } // retrieve MySQL databases $databases = PMA_GetDatabases(); // check if BS tables exist for each database foreach ($databases as $db_key=>$db_name) { $bs_databases[$db_name] = $bs_tables; PMA_TablesExist($bs_databases[$db_name], $db_name); } // set BS databases in PMA configuration $PMA_Config->set('BLOBSTREAMABLE_DATABASES', $bs_databases);}/** * checks whether a set of plugins exist * * @access public * @param array - a list of plugin names and accompanying library filenames to check for * @uses PMA_DBI_query() * @uses PMA_DBI_fetch_assoc()*/function PMA_PluginsExist(&$plugins){ if (PMA_MYSQL_INT_VERSION < 50109) { return; } // run query to retrieve MySQL plugins $query = "SHOW PLUGINS"; $result = PMA_DBI_query($query); // while there are records to parse while ($data = @PMA_DBI_fetch_assoc($result)) { // reset plugin state $state = TRUE; // check if required plugins exist foreach ($plugins as $plugin_key=>$plugin) if (!$plugin['Exists']) if ( strtolower($data['Library']) == strtolower($plugin['Library']) && $data['Status'] == "ACTIVE" ) $plugins[$plugin_key]['Exists'] = TRUE; else if ($state) $state = FALSE; // break if all necessary plugins are found before all records are parsed if ($state) break; } // end while ($data = @PMA_DBI_fetch_assoc($result))}/** * checks whether a given set of tables exist in a given database * * @access public * @param array - list of tables to look for * @param string - name of database * @uses PMA_DBI_select_db() * @uses PMA_DBI_query() * @uses PMA_DBI_fetch_assoc() */function PMA_TablesExist(&$tables, $db_name){ // select specified database PMA_DBI_select_db($db_name); // run query to retrieve tables in specified database $query = "SHOW TABLES"; $result = PMA_DBI_query($query); // while there are records to parse while ($data = @PMA_DBI_fetch_assoc($result)) { $state = TRUE; // check if necessary tables exist foreach ($tables as $table_key=>$table) if (!$table['Exists']) if ($data['Tables_in_' . $db_name] == $table_key) $tables[$table_key]['Exists'] = TRUE; else if ($state) $state = FALSE; // break if necessary tables are found before all records are parsed if ($state) break; } // end while ($data = @PMA_DBI_fetch_assoc($result))}/** * returns a list of databases * * @access public * @uses PMA_DBI_query() * @uses PMA_DBI_fetch_assoc() * @return array - list of databases acquired via MySQL*/function PMA_GetDatabases(){ // run query to retrieve databases $query = "SHOW DATABASES"; $result = PMA_DBI_query($query); $databases = array(); // while there are records to parse while ($data = @PMA_DBI_fetch_assoc($result)) $databases[] = $data['Database']; // return list of databases return $databases;}/** * sets BLOBStreaming variables to a list of specified arguments * @access public * @uses PMA_DBI_query() * @returns boolean - success of variables setup*/function PMA_BS_SetVariables($bs_variables)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?