From 56ebe05af73115e9c6928beb49db846fbbda460a Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Thu, 22 Jul 2010 13:15:27 -0400 Subject: [PATCH] blob streaming code cleanup (work in progress) --- bs_change_mime_type.php | 24 +- bs_disp_as_mime_type.php | 15 +- bs_play_media.php | 22 +- db_structure.php | 12 +- libraries/File.class.php | 102 ++++---- libraries/StorageEngine.class.php | 7 +- libraries/blobstreaming.lib.php | 400 +++++++++++++++--------------- libraries/common.inc.php | 4 +- libraries/common.lib.php | 21 +- libraries/core.lib.php | 9 +- libraries/display_tbl.lib.php | 14 +- libraries/engines/pbms.lib.php | 54 ++-- libraries/engines/pbxt.lib.php | 42 ++-- server_engines.php | 31 ++- tbl_change.php | 31 ++- 15 files changed, 389 insertions(+), 399 deletions(-) diff --git a/bs_change_mime_type.php b/bs_change_mime_type.php index 51cf6cb3ef0d..edefae144e40 100644 --- a/bs_change_mime_type.php +++ b/bs_change_mime_type.php @@ -32,19 +32,17 @@ // necessary variables exist if ($bsDB && $bsTable && $bsReference && $bsNewMIMEType) { - if (PMA_BS_SetContentType($bsDB, $bsTable, $bsReference, $bsNewMIMEType)) - { - // determine redirector page - $newLoc = $cfg['PmaAbsoluteUri'] . 'sql.php?' . PMA_generate_common_url ('','', '&') . (isset($bsDB) ? '&db=' . urlencode($bsDB) : '') . (isset($bsTable) ? '&table=' . urlencode($bsTable) : '') . (isset($token) ? '&token=' . urlencode($token) : '') . (isset($goto) ? '&goto=' . urlencode($goto) : '') . '&reload=1&purge=1'; - - // redirect to specified page - ?> - - + + diff --git a/bs_disp_as_mime_type.php b/bs_disp_as_mime_type.php index 18fc20169376..085d888236d6 100644 --- a/bs_disp_as_mime_type.php +++ b/bs_disp_as_mime_type.php @@ -25,15 +25,21 @@ // Get the blob streaming URL $filename = PMA_BS_getURL($reference); -if (empty($filename)) die('No blob streaming server configured!'); +if (empty($filename)) { + die(__('No blob streaming server configured!')); +} $hdrs = get_headers($filename, 1); -if ($hdrs === FALSE) die('Failed to fetch headers'); +if ($hdrs === FALSE) { + die(__('Failed to fetch headers')); +} $fHnd = fopen($filename, "rb"); -if ($fHnd === FALSE) die('Failed to open remote URL'); +if ($fHnd === FALSE) { + die(__('Failed to open remote URL')); +} $f_size = $hdrs['Content-Length']; @@ -53,8 +59,9 @@ $content .= fread($fHnd, $f_size); $pos = strlen($content); - if ($pos >= $f_size) + if ($pos >= $f_size) { break; + } } echo $content; diff --git a/bs_play_media.php b/bs_play_media.php index e1081f9e01b7..fe6f57425051 100644 --- a/bs_play_media.php +++ b/bs_play_media.php @@ -15,7 +15,7 @@ $mediaType = isset($_REQUEST['media_type']) ? $_REQUEST['media_type'] : NULL; /* - * @var string indicates whether media type is of custom type + * @var string indicates whether media type is of custom type */ $customType = isset($_REQUEST['custom_type']) ? $_REQUEST['custom_type'] : false; @@ -25,16 +25,16 @@ $bsReference = isset($_REQUEST['bs_reference']) ? $_REQUEST['bs_reference'] : NULL; // if media type and BS reference are specified - if (isset($mediaType) && isset($bsReference)) - { - if (isset($customType) && $customType) - $bs_file_path = 'bs_disp_as_mime_type.php' . PMA_generate_common_url(array('reference' => $bsReference, 'c_type' => $mediaType)); - else { - // Get the BLOB streaming URL - $bs_file_path = PMA_BS_getURL($bsReference); - if (empty($bs_file_path)) die('No blob streaming server configured!'); - } - + if (isset($mediaType) && isset($bsReference)) { + if (isset($customType) && $customType) { + $bs_file_path = 'bs_disp_as_mime_type.php' . PMA_generate_common_url(array('reference' => $bsReference, 'c_type' => $mediaType)); + } else { + // Get the BLOB streaming URL + $bs_file_path = PMA_BS_getURL($bsReference); + if (empty($bs_file_path)) { + die(__('No blob streaming server configured!')); + } + } ?> diff --git a/db_structure.php b/db_structure.php index e73c0276383c..077dcab45789 100644 --- a/db_structure.php +++ b/db_structure.php @@ -150,17 +150,13 @@ $odd_row = true; $sum_row_count_pre = ''; -// added by rajk - for blobstreaming -$PMA_Config = $GLOBALS['PMA_Config']; - $tableReductionCount = 0; // the amount to reduce the table count by foreach ($tables as $keyname => $each_table) { - - if (PMA_BS_IsHiddenTable($keyname)) { - $tableReductionCount++; - continue; - } + if (PMA_BS_IsHiddenTable($keyname)) { + $tableReductionCount++; + continue; + } // Get valid statistics whatever is the table type diff --git a/libraries/File.class.php b/libraries/File.class.php index 4aec35c7034a..83f5d14deb5b 100644 --- a/libraries/File.class.php +++ b/libraries/File.class.php @@ -279,29 +279,26 @@ function setUploadedFromTblChangeRequest($key, $primary = null) $is_bs_upload = FALSE; // check if this field requires a repository upload - if (isset($_REQUEST['upload_blob_repo_' . $key])) + if (isset($_REQUEST['upload_blob_repo_' . $key])) { $is_bs_upload = ($_REQUEST['upload_blob_repo_' . $key]['multi_edit'][0] == "on") ? TRUE : FALSE; - + } // if request is an upload to the BLOB repository - if ($is_bs_upload) - { - $bs_db = $_REQUEST['db']; - $bs_table = $_REQUEST['table']; - $tmp_filename = $file['tmp_name']; - $tmp_file_type = $file['type']; - - if (!$tmp_file_type) - $tmp_file_type = NULL; - - - if (!$bs_db || !$bs_table) - { - $this->_error_message = $GLOBALS['strUploadErrorUnknown']; - return FALSE; - } - $blob_url = PMA_BS_UpLoadFile($bs_db, $bs_table, $tmp_file_type, $tmp_filename); - PMA_File::setRecentBLOBReference($blob_url); + if ($is_bs_upload) { + $bs_db = $_REQUEST['db']; + $bs_table = $_REQUEST['table']; + $tmp_filename = $file['tmp_name']; + $tmp_file_type = $file['type']; + + if (! $tmp_file_type) { + $tmp_file_type = NULL; + } + if (! $bs_db || ! $bs_table) { + $this->_error_message = $GLOBALS['strUploadErrorUnknown']; + return FALSE; + } + $blob_url = PMA_BS_UpLoadFile($bs_db, $bs_table, $tmp_file_type, $tmp_filename); + PMA_File::setRecentBLOBReference($blob_url); } // end if ($is_bs_upload) // check for file upload errors @@ -399,45 +396,42 @@ function setSelectedFromTblChangeRequest($key, $primary = null) $is_bs_upload = FALSE; // check if this field requires a repository upload - if (isset($_REQUEST['upload_blob_repo_' . $key])) + if (isset($_REQUEST['upload_blob_repo_' . $key])) { $is_bs_upload = ($_REQUEST['upload_blob_repo_' . $key]['multi_edit'][0] == "on") ? TRUE : FALSE; + } // is a request to upload file to BLOB repository using uploadDir mechanism - if ($is_bs_upload) - { - $bs_db = $_REQUEST['db']; - $bs_table = $_REQUEST['table']; - $tmp_filename = $GLOBALS['cfg']['UploadDir'] . '/' . $_REQUEST['fields_uploadlocal_' . $key]['multi_edit'][$primary]; - - // check if fileinfo library exists - if ($PMA_Config->get('FILEINFO_EXISTS')) - { - // attempt to init fileinfo - $finfo = finfo_open(FILEINFO_MIME); - - // fileinfo exists - if ($finfo) - { - // pass in filename to fileinfo and close fileinfo handle after - $tmp_file_type = finfo_file($finfo, $tmp_filename); - finfo_close($finfo); - } - } - else // no fileinfo library exists, use file command - $tmp_file_type = exec("file -bi " . escapeshellarg($tmp_filename)); - - if (!$tmp_file_type) - $tmp_file_type = NULL; - + if ($is_bs_upload) { + $bs_db = $_REQUEST['db']; + $bs_table = $_REQUEST['table']; + $tmp_filename = $GLOBALS['cfg']['UploadDir'] . '/' . $_REQUEST['fields_uploadlocal_' . $key]['multi_edit'][$primary]; + + // check if fileinfo library exists + if ($PMA_Config->get('FILEINFO_EXISTS')) { + // attempt to init fileinfo + $finfo = finfo_open(FILEINFO_MIME); + + // fileinfo exists + if ($finfo) { + // pass in filename to fileinfo and close fileinfo handle after + $tmp_file_type = finfo_file($finfo, $tmp_filename); + finfo_close($finfo); + } + } else { + // no fileinfo library exists, use file command + $tmp_file_type = exec("file -bi " . escapeshellarg($tmp_filename)); + } - if (!$bs_db || !$bs_table) - { - $this->_error_message = $GLOBALS['strUploadErrorUnknown']; - return FALSE; - } - $blob_url = PMA_BS_UpLoadFile($bs_db, $bs_table, $tmp_file_type, $tmp_filename); - PMA_File::setRecentBLOBReference($blob_url); + if (! $tmp_file_type) { + $tmp_file_type = NULL; + } + if (! $bs_db || !$bs_table) { + $this->_error_message = $GLOBALS['strUploadErrorUnknown']; + return FALSE; + } + $blob_url = PMA_BS_UpLoadFile($bs_db, $bs_table, $tmp_file_type, $tmp_filename); + PMA_File::setRecentBLOBReference($blob_url); } // end if ($is_bs_upload) return $this->setLocalSelectedFile($_REQUEST['fields_uploadlocal_' . $key]['multi_edit'][$primary]); diff --git a/libraries/StorageEngine.class.php b/libraries/StorageEngine.class.php index 675528c04c71..71b363625c84 100644 --- a/libraries/StorageEngine.class.php +++ b/libraries/StorageEngine.class.php @@ -139,8 +139,9 @@ static public function getEngine($engine) */ static public function isValid($engine) { - if ($engine == "PBMS") - return TRUE; + if ($engine == "PBMS") { + return TRUE; + } $storage_engines = PMA_StorageEngine::getStorageEngines(); return isset($storage_engines[$engine]); } @@ -303,7 +304,7 @@ function __construct($engine) $this->support = PMA_ENGINE_SUPPORT_NO; } } else { - $this->engine_init(); + $this->engine_init(); } } diff --git a/libraries/blobstreaming.lib.php b/libraries/blobstreaming.lib.php index e6c59738c5eb..abbe04735893 100644 --- a/libraries/blobstreaming.lib.php +++ b/libraries/blobstreaming.lib.php @@ -6,36 +6,38 @@ function initPBMSDatabase() { - $query = "create database IF NOT EXISTS pbms;"; // If no other choice then try this. - /* - * The user may not have privileges to create the 'pbms' database - * so if it doesn't exist then we perform a select on a pbms system - * table in an already existing database which will cause the PBMS - * daemon to create the 'pbms' database. - */ - $db_array =PMA_DBI_fetch_result('SHOW DATABASES;'); - if (!empty($db_array)) { - $target = ""; - foreach ($db_array as $current_db) { - if ($current_db == 'pbms') - return TRUE; - - if ($target == "") { - if (($current_db != 'pbxt') && ($current_db != 'mysql') && ($current_db != 'information_schema')) - $target = $current_db; - } - } + $query = "create database IF NOT EXISTS pbms;"; // If no other choice then try this. + /* + * The user may not have privileges to create the 'pbms' database + * so if it doesn't exist then we perform a select on a pbms system + * table in an already existing database which will cause the PBMS + * daemon to create the 'pbms' database. + */ + $db_array = PMA_DBI_fetch_result('SHOW DATABASES;'); + if (! empty($db_array)) { + $target = ""; + foreach ($db_array as $current_db) { + if ($current_db == 'pbms') { + return TRUE; + } + if ($target == "") { + if (($current_db != 'pbxt') && ($current_db != 'mysql') && ($current_db != 'information_schema')) { + $target = $current_db; + } + } + } - if ($target != "") - $query = "select * from $target.pbms_metadata_header"; // If it exists this table will not contain much - } + if ($target != "") { + $query = "select * from $target.pbms_metadata_header"; // If it exists this table will not contain much + } + } - $result = PMA_DBI_query($query ); - if (!$result) - return FALSE; - - return TRUE; - } + $result = PMA_DBI_query($query ); + if (! $result) { + return FALSE; + } + return TRUE; +} /** * checks whether the necessary plugins for BLOBStreaming exist @@ -95,23 +97,23 @@ function checkBLOBStreamingPlugins() // Retrieve MySQL plugins $existing_plugins = PMA_DBI_fetch_result('SHOW PLUGINS'); - foreach ($existing_plugins as $one_existing_plugin) { + foreach ($existing_plugins as $one_existing_plugin) { // check if required plugins exist - if ( strtolower($one_existing_plugin['Library']) == 'libpbms.so' + if ( strtolower($one_existing_plugin['Library']) == 'libpbms.so' && $one_existing_plugin['Status'] == "ACTIVE") { - $has_blobstreaming = true; - break; - } + $has_blobstreaming = true; + break; + } } - unset($existing_plugins, $one_existing_plugin); + unset($existing_plugins, $one_existing_plugin); } // set variable indicating BS plugin existence $PMA_Config->set('BLOBSTREAMING_PLUGINS_EXIST', $has_blobstreaming); if ($has_blobstreaming) { - $bs_variables = PMA_BS_GetVariables(); - + $bs_variables = PMA_BS_GetVariables(); + // if no BS variables exist, set plugin existence to false and return if (count($bs_variables) <= 0) { $PMA_Config->set('BLOBSTREAMING_PLUGINS_EXIST', FALSE); @@ -136,7 +138,7 @@ function checkBLOBStreamingPlugins() $PMA_Config->set('PHP_PBMS_EXISTS', FALSE); $PMA_Config->set('FILEINFO_EXISTS', FALSE); - // check if PECL's fileinfo library exist + // check if PECL's fileinfo library exist $finfo = NULL; if (function_exists("finfo_open")) { @@ -148,7 +150,7 @@ function checkBLOBStreamingPlugins() $PMA_Config->set('FILEINFO_EXISTS', TRUE); finfo_close($finfo); } // end if (!empty($finfo)) - + } else { PMA_cacheSet('skip_blobstreaming', true, true); return FALSE; @@ -223,8 +225,8 @@ function PMA_BS_GetVariables() //======================== function PMA_BS_ReportPBMSError($msg) { - $tmp_err = pbms_error(); - PMA_showMessage("PBMS error, $msg $tmp_err"); + $tmp_err = pbms_error(); + PMA_showMessage("PBMS error, $msg $tmp_err"); } //------------ @@ -238,20 +240,21 @@ function PMA_do_connect($db_name, $quiet) // generate bs reference link $pbms_host = $PMA_Config->get('BLOBSTREAMING_HOST'); - $pbms_port = $PMA_Config->get('BLOBSTREAMING_PORT'); + $pbms_port = $PMA_Config->get('BLOBSTREAMING_PORT'); - if (pbms_connect($pbms_host, $pbms_port, $db_name) == FALSE) { - if ($quiet == FALSE) - PMA_BS_ReportPBMSError("PBMS Connectiuon failed: pbms_connect($pbms_host, $pbms_port, $db_name)"); - return FALSE; - } - return TRUE; + if (pbms_connect($pbms_host, $pbms_port, $db_name) == FALSE) { + if ($quiet == FALSE) { + PMA_BS_ReportPBMSError("PBMS Connectiuon failed: pbms_connect($pbms_host, $pbms_port, $db_name)"); + } + return FALSE; + } + return TRUE; } //------------ function PMA_do_disconnect() { - pbms_close(); + pbms_close(); } //------------ @@ -261,76 +264,76 @@ function PMA_do_disconnect() */ function PMA_BS_IsPBMSReference($bs_reference, $db_name) { - if (PMA_cacheGet('skip_blobstreaming', true)) - return FALSE; - - if (PMA_do_connect($db_name, TRUE) == FALSE) { - return FALSE; - } + if (PMA_cacheGet('skip_blobstreaming', true)) { + return FALSE; + } + + if (PMA_do_connect($db_name, TRUE) == FALSE) { + return FALSE; + } $ok = pbms_is_blob_reference($bs_reference); - PMA_do_disconnect(); - return $ok ; + PMA_do_disconnect(); + return $ok ; } //------------ function PMA_BS_CreateReferenceLink($bs_reference, $db_name) { - if (PMA_do_connect($db_name, FALSE) == FALSE) { - return 'Error'; - } - - if (pbms_get_info($bs_reference) == FALSE) { - PMA_BS_ReportPBMSError("PBMS get BLOB info failed: pbms_get_info($bs_reference)"); - PMA_do_disconnect(); - return 'Error'; - } + if (PMA_do_connect($db_name, FALSE) == FALSE) { + return 'Error'; + } + + if (pbms_get_info($bs_reference) == FALSE) { + PMA_BS_ReportPBMSError("PBMS get BLOB info failed: pbms_get_info($bs_reference)"); + PMA_do_disconnect(); + return 'Error'; + } $content_type = pbms_get_metadata_value("Content-type"); if ($content_type == FALSE) { PMA_BS_ReportPBMSError("PMA_BS_CreateReferenceLink($bs_reference, $db_name): get BLOB Content-type failed: "); } - - PMA_do_disconnect(); - - if (!$content_type) - $content_type = "image/jpeg"; - - $bs_url = PMA_BS_getURL($bs_reference); - if (empty($bs_url)) { - PMA_BS_ReportPBMSError("No blob streaming server configured!"); - return 'Error'; + + PMA_do_disconnect(); + + if (! $content_type) { + $content_type = "image/jpeg"; + } + + $bs_url = PMA_BS_getURL($bs_reference); + if (empty($bs_url)) { + PMA_BS_ReportPBMSError("No blob streaming server configured!"); + return 'Error'; } - - $output = "$content_type"; - - // specify custom HTML for various content types - switch ($content_type) - { - // no content specified - case NULL: - $output = "NULL"; - break; - // image content - case 'image/jpeg': - case 'image/png': - $output .= ' (' . __('View image') . ')'; - break; + + $output = "$content_type"; + + // specify custom HTML for various content types + switch ($content_type) { + // no content specified + case NULL: + $output = "NULL"; + break; + // image content + case 'image/jpeg': + case 'image/png': + $output .= ' (' . __('View image') . ')'; + break; // audio content - case 'audio/mpeg': - $output .= ' (' . __('Play audio'). ')'; - break; - // video content - case 'application/x-flash-video': - case 'video/mpeg': - $output .= ' (' . __('View video') . ')'; - break; - // unsupported content. specify download - default: - $output .= ' (' . __('Download file'). ')'; - } + case 'audio/mpeg': + $output .= ' (' . __('Play audio'). ')'; + break; + // video content + case 'application/x-flash-video': + case 'video/mpeg': + $output .= ' (' . __('View video') . ')'; + break; + // unsupported content. specify download + default: + $output .= ' (' . __('Download file'). ')'; + } -//PMA_showMessage("PMA_BS_CreateReferenceLink($bs_reference, $db_name): $output"); - return $output; + return $output; } //------------ @@ -340,31 +343,36 @@ function PMA_BS_CreateReferenceLink($bs_reference, $db_name) // they are not currently needed. function PMA_BS_IsTablePBMSEnabled($db_name, $tbl_name, $tbl_type) { - if (PMA_cacheGet('skip_blobstreaming', true)) - return FALSE; - - if ((isset($tbl_type) == FALSE) || (strlen($tbl_type) == 0)) - return FALSE; - + if (PMA_cacheGet('skip_blobstreaming', true)) { + return FALSE; + } + + if ((isset($tbl_type) == FALSE) || (strlen($tbl_type) == 0)) { + return FALSE; + } + // load PMA configuration $PMA_Config = $GLOBALS['PMA_Config']; // return if unable to load PMA configuration - if (empty($PMA_Config)) + if (empty($PMA_Config)) { return FALSE; - - if (!$PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST') ) + } + + if (! $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST')) { return FALSE; + } + + // This information should be cached rather than selecting it each time. + //$query = "SELECT count(*) FROM information_schema.TABLES T, pbms.pbms_enabled E where T.table_schema = ". PMA_backquote($db_name) . " and T.table_name = ". PMA_backquote($tbl_name) . " and T.engine = E.name"; + $query = "SELECT count(*) FROM pbms.pbms_enabled E where E.name = '" . PMA_sqlAddslashes($tbl_type) . "'"; + $result = PMA_DBI_query($query); - // This information should be cached rather than selecting it each time. - //$query = "SELECT count(*) FROM information_schema.TABLES T, pbms.pbms_enabled E where T.table_schema = ". PMA_backquote($db_name) . " and T.table_name = ". PMA_backquote($tbl_name) . " and T.engine = E.name"; - $query = "SELECT count(*) FROM pbms.pbms_enabled E where E.name = '". PMA_sqlAddslashes($tbl_type) . "'" ; - $result = PMA_DBI_query($query); + $data = PMA_DBI_fetch_row($result); + if ($data[0] == 1) { + return TRUE; + } - $data = PMA_DBI_fetch_row($result); - if ($data[0] == 1) - return TRUE; - return FALSE; } @@ -372,107 +380,97 @@ function PMA_BS_IsTablePBMSEnabled($db_name, $tbl_name, $tbl_type) function PMA_BS_UpLoadFile($db_name, $tbl_name, $file_type, $file_name) { - if (PMA_cacheGet('skip_blobstreaming', true)) - return FALSE; + if (PMA_cacheGet('skip_blobstreaming', true)) { + return FALSE; + } - if (PMA_do_connect($db_name, FALSE) == FALSE) { - return FALSE; - } - - $fh = fopen($file_name, 'r'); - if (!$fh) { - PMA_do_disconnect(); - PMA_showMessage("Could not open file: $file_name"); - return FALSE; - } - - pbms_add_metadata("Content-type", $file_type); - - $pbms_blob_url = pbms_read_stream($fh, filesize($file_name), $tbl_name); - if (!$pbms_blob_url) { - PMA_BS_ReportPBMSError("pbms_read_stream() Failed"); + if (PMA_do_connect($db_name, FALSE) == FALSE) { + return FALSE; + } + + $fh = fopen($file_name, 'r'); + if (! $fh) { + PMA_do_disconnect(); + PMA_showMessage("Could not open file: $file_name"); + return FALSE; } - //PMA_showMessage(" PMA_BS_UpLoadFile($db_name, $tbl_name, $file_type, $file_name): $pbms_blob_url"); - fclose($fh); - PMA_do_disconnect(); - return $pbms_blob_url; + pbms_add_metadata("Content-type", $file_type); + + $pbms_blob_url = pbms_read_stream($fh, filesize($file_name), $tbl_name); + if (! $pbms_blob_url) { + PMA_BS_ReportPBMSError("pbms_read_stream() Failed"); + } + + fclose($fh); + PMA_do_disconnect(); + return $pbms_blob_url; } //------------ function PMA_BS_SetContentType($db_name, $bsTable, $blobReference, $contentType) { - if (PMA_cacheGet('skip_blobstreaming', true)) - return FALSE; - - // This is a really ugly way to do this but currently there is nothing better. - // In a future version of PBMS the system tables will be redesigned to make this - // more eficient. - $query = "SELECT Repository_id, Repo_blob_offset FROM pbms_reference WHERE Blob_url='" . PMA_sqlAddslashes($blobReference) . "'"; -//error_log(" PMA_BS_SetContentType: $query\n", 3, "/tmp/mylog"); - $result = PMA_DBI_query($query); -//error_log(" $query\n", 3, "/tmp/mylog"); - - // if record exists - if ($data = PMA_DBI_fetch_assoc($result)) - { - $where = "WHERE Repository_id=" . $data['Repository_id'] . " AND Repo_blob_offset=" . $data['Repo_blob_offset'] ; - $query = "SELECT name from pbms_metadata $where"; - $result = PMA_DBI_query($query); + if (PMA_cacheGet('skip_blobstreaming', true)) { + return FALSE; + } - if (PMA_DBI_num_rows($result) == 0) - $query = "INSERT into pbms_metadata Values( ". $data['Repository_id'] . ", " . $data['Repo_blob_offset'] . ", 'Content_type', '" . PMA_sqlAddslashes($contentType) . "')"; - else - $query = "UPDATE pbms_metadata SET name = 'Content_type', Value = '" . PMA_sqlAddslashes($contentType) . "' $where"; + // This is a really ugly way to do this but currently there is nothing better. + // In a future version of PBMS the system tables will be redesigned to make this + // more eficient. + $query = "SELECT Repository_id, Repo_blob_offset FROM pbms_reference WHERE Blob_url='" . PMA_sqlAddslashes($blobReference) . "'"; + //error_log(" PMA_BS_SetContentType: $query\n", 3, "/tmp/mylog"); + $result = PMA_DBI_query($query); + //error_log(" $query\n", 3, "/tmp/mylog"); -//error_log("$query\n", 3, "/tmp/mylog"); - PMA_DBI_query($query); - +// if record exists + if ($data = PMA_DBI_fetch_assoc($result)) { + $where = "WHERE Repository_id=" . $data['Repository_id'] . " AND Repo_blob_offset=" . $data['Repo_blob_offset'] ; + $query = "SELECT name from pbms_metadata $where"; + $result = PMA_DBI_query($query); - } else { -// if ($result == FALSE) { -// $err = PMA_DBI_getError(); -// error_log("MySQL ERROR: $err\n", 3, "/tmp/mylog"); -// } else -// error_log("No results: $query\n", 3, "/tmp/mylog"); - return FALSE; - } - - return TRUE; + if (PMA_DBI_num_rows($result) == 0) { + $query = "INSERT into pbms_metadata Values( ". $data['Repository_id'] . ", " . $data['Repo_blob_offset'] . ", 'Content_type', '" . PMA_sqlAddslashes($contentType) . "')"; + } else { + $query = "UPDATE pbms_metadata SET name = 'Content_type', Value = '" . PMA_sqlAddslashes($contentType) . "' $where"; + } +//error_log("$query\n", 3, "/tmp/mylog"); + PMA_DBI_query($query); + } else { + return FALSE; + } + return TRUE; } //------------ function PMA_BS_IsHiddenTable($table) { - switch ($table) { - case 'pbms_repository' : - case 'pbms_reference' : - case 'pbms_metadata' : - case 'pbms_metadata_header' : - case 'pbms_dump' : - return TRUE; - } - - return FALSE; + switch ($table) { + case 'pbms_repository' : + case 'pbms_reference' : + case 'pbms_metadata' : + case 'pbms_metadata_header' : + case 'pbms_dump' : + return TRUE; + } + return FALSE; } //------------ function PMA_BS_getURL($reference) { - // load PMA configuration - $PMA_Config = $GLOBALS['PMA_Config']; - if (empty($PMA_Config)) - return FALSE; - - // retrieve BS server variables from PMA configuration - $bs_server = $PMA_Config->get('BLOBSTREAMING_SERVER'); - if (empty($bs_server)) - return FALSE; - - $bs_url = 'http://' . $bs_server . '/' . rtrim($reference); -//PMA_showMessage(" PMA_BS_getURL($reference): $bs_url"); - return $bs_url; + // load PMA configuration + $PMA_Config = $GLOBALS['PMA_Config']; + if (empty($PMA_Config)) { + return FALSE; + } + // retrieve BS server variables from PMA configuration + $bs_server = $PMA_Config->get('BLOBSTREAMING_SERVER'); + if (empty($bs_server)) { + return FALSE; + } + + $bs_url = 'http://' . $bs_server . '/' . rtrim($reference); + return $bs_url; } - ?> diff --git a/libraries/common.inc.php b/libraries/common.inc.php index 971619850c81..d1a6d948f1d1 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -788,7 +788,7 @@ $_SESSION['PMA_Theme_Manager']->setThemeCookie(); - if (! empty($cfg['Server'])) { + if (! empty($cfg['Server'])) { /** * Loads the proper database interface for this server @@ -953,7 +953,7 @@ // checks for blobstreaming plugins and databases that support // blobstreaming (by having the necessary tables for blobstreaming) checkBLOBStreamingPlugins(); - + } // end if !defined('PMA_MINIMUM_COMMON') // remove sensitive values from session diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 672afc34d271..1010b2c8cc49 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -654,19 +654,19 @@ function PMA_mysqlDie($error_message = '', $the_query = '', $back_url .= '?no_history=true'; } - $_SESSION['Import_message']['go_back_url'] = $back_url; + $_SESSION['Import_message']['go_back_url'] = $back_url; $error_msg_output .= '
'; $error_msg_output .= '[ ' . __('Back') . ' ]'; $error_msg_output .= '
' . "\n\n"; - } + } - echo $error_msg_output; - /** - * display footer and exit - */ + echo $error_msg_output; + /** + * display footer and exit + */ - require_once './libraries/footer.inc.php'; + require_once './libraries/footer.inc.php'; } else { echo $error_msg_output; } @@ -793,10 +793,9 @@ function PMA_getTableList($db, $tables = null, $limit_offset = 0, $limit_count = foreach ($tables as $table_name => $table) { // if BS tables exist - if (PMA_BS_IsHiddenTable($table_name)) { - continue; - } - + if (PMA_BS_IsHiddenTable($table_name)) { + continue; + } // check for correct row count if (null === $table['Rows']) { diff --git a/libraries/core.lib.php b/libraries/core.lib.php index c2cdc5ff080a..dcbf1778be84 100644 --- a/libraries/core.lib.php +++ b/libraries/core.lib.php @@ -311,10 +311,11 @@ function PMA_getTableCount($db) $num_tables = PMA_DBI_num_rows($tables); // do not count hidden blobstreaming tables - while ((($num_tables > 0)) && $data = PMA_DBI_fetch_assoc($tables)) { - if (PMA_BS_IsHiddenTable($data['Tables_in_' . $db])) - $num_tables--; - } + while ((($num_tables > 0)) && $data = PMA_DBI_fetch_assoc($tables)) { + if (PMA_BS_IsHiddenTable($data['Tables_in_' . $db])) { + $num_tables--; + } + } PMA_DBI_free_result($tables); } else { diff --git a/libraries/display_tbl.lib.php b/libraries/display_tbl.lib.php index 2df652f13b9e..a435e3b90c42 100644 --- a/libraries/display_tbl.lib.php +++ b/libraries/display_tbl.lib.php @@ -1285,10 +1285,9 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { $vertical_display['data'][$row_no][$i] = ' NULL' . "\n"; } else { // for blobstreaming - - // if valid BS reference exists - if (PMA_BS_IsPBMSReference($row[$i], $db)) { - $blobtext = PMA_BS_CreateReferenceLink($row[$i], $db); + // if valid BS reference exists + if (PMA_BS_IsPBMSReference($row[$i], $db)) { + $blobtext = PMA_BS_CreateReferenceLink($row[$i], $db); } else { $blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta, $_url_params); } @@ -1340,9 +1339,8 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { // user asked to see the real contents of BINARY // fields if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && PMA_contains_nonprintable_ascii($row[$i])) { - $row[$i] = bin2hex($row[$i]); - } - else { + $row[$i] = bin2hex($row[$i]); + } else { $row[$i] = htmlspecialchars(PMA_replace_binary_contents($row[$i])); } } else { @@ -1696,7 +1694,7 @@ function PMA_displayTable_checkConfigParams() } else { // display_binary_as_hex config option if (isset($GLOBALS['cfg']['DisplayBinaryAsHex']) && true === $GLOBALS['cfg']['DisplayBinaryAsHex']) { - $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true; + $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true; } } diff --git a/libraries/engines/pbms.lib.php b/libraries/engines/pbms.lib.php index af403ca6e1e2..2a51c92d4972 100644 --- a/libraries/engines/pbms.lib.php +++ b/libraries/engines/pbms.lib.php @@ -18,12 +18,12 @@ class PMA_StorageEngine_pbms extends PMA_StorageEngine */ function engine_init() { - $this->engine = "PBMS"; - $this->title = "PrimeBase Media Streaming Daemon"; - $this->comment = "Provides BLOB streaming service for storage engines,"; - $this->support = PMA_ENGINE_SUPPORT_YES; - } - + $this->engine = "PBMS"; + $this->title = "PrimeBase Media Streaming Daemon"; + $this->comment = "Provides BLOB streaming service for storage engines,"; + $this->support = PMA_ENGINE_SUPPORT_YES; + } + function getVariables() { return array( @@ -64,16 +64,16 @@ function getVariables() ), ); } - - //-------------------- - function getInfoPages() + + //-------------------- + function getInfoPages() { $pages = array(); - $pages['Documentation'] = __('Documentation'); + $pages['Documentation'] = __('Documentation'); return $pages; } - //-------------------- + //-------------------- function getPage($id) { if (! array_key_exists($id, $this->getInfoPages())) { @@ -87,27 +87,27 @@ function getPage($id) function getPageConfigure() { - } + } function getPageDocumentation() { - $output = '

Documentation and furtther information about PBMS can be found on ' . "\n" - . 'The PrimeBase Media Streaming home page.

' . "\n" - . '' . "\n" + $output = '

Documentation and further information about PBMS can be found on ' . "\n" + . 'The PrimeBase Media Streaming home page.

' . "\n" + . '

' . "\n" . '' . "\n" - . '' . "\n" - . '' . "\n" - . '' . "\n"; + . '' . "\n" + . '

' . "\n" + . 'Related Links' . "\n" + . '
' . "\n" + . 'The PrimeBase Media Streaming Blog by Barry Leslie

' . "\n" + . 'PrimeBase XT Home Page

' . "\n" + . '' . "\n" + . '' . "\n" + . '' . "\n" + . '' . "\n"; - return $output; - } + return $output; + } } ?> diff --git a/libraries/engines/pbxt.lib.php b/libraries/engines/pbxt.lib.php index 724369936d26..fbc6ce68a53d 100644 --- a/libraries/engines/pbxt.lib.php +++ b/libraries/engines/pbxt.lib.php @@ -98,16 +98,16 @@ function resolveTypeSize($formatted_size) } return PMA_formatByteDown($value); } - - //-------------------- - function getInfoPages() + + //-------------------- + function getInfoPages() { $pages = array(); - $pages['Documentation'] = __('Documentation'); + $pages['Documentation'] = __('Documentation'); return $pages; } - //-------------------- + //-------------------- function getPage($id) { if (! array_key_exists($id, $this->getInfoPages())) { @@ -121,23 +121,23 @@ function getPage($id) function getPageDocumentation() { - $output = '

Documentation and furtther information about PBXT can be found on the ' . "\n" - . 'PrimeBase XT Home Page.

' . "\n" - . '' . "\n" - . '' . "\n" - . '' . "\n" - . '' . "\n" - . '' . "\n"; + $output = '

Documentation and further information about PBXT can be found on the ' . "\n" + . 'PrimeBase XT Home Page.

' . "\n" + . '' . "\n" + . '' . "\n" + . '' . "\n" + . '' . "\n" + . '' . "\n"; - return $output; - } + return $output; + } } ?> diff --git a/server_engines.php b/server_engines.php index 2179f5fe8f40..5ef4e6fbee4e 100644 --- a/server_engines.php +++ b/server_engines.php @@ -1,9 +1,8 @@ get('BLOBSTREAMING_PLUGINS_EXIST')) { - // Special case for PBMS daemon which is not listed as an engine - echo '' . "\n" - . ' ' . "\n" - . ' ' . "PBMS\n" - . ' ' . "\n" - . ' ' . htmlspecialchars("PrimeBase MediaStream (PBMS) daemon") . '' . "\n" - . '' . "\n"; - } - + $PMA_Config = $GLOBALS['PMA_Config']; + if ($PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST')) { + // Special case for PBMS daemon which is not listed as an engine + echo '' . "\n" + . ' ' . "\n" + . ' ' . "PBMS\n" + . ' ' . "\n" + . ' ' . htmlspecialchars("PrimeBase MediaStream (PBMS) daemon") . '' . "\n" + . '' . "\n"; + } + unset($odd_row, $engine, $details); echo '' . "\n" . '' . "\n"; diff --git a/tbl_change.php b/tbl_change.php index 8cde1b2c9d26..d8486ba3c598 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -456,17 +456,17 @@ } else { // special binary "characters" if ($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) { - if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) { - $vrow[$field['Field']] = bin2hex($vrow[$field['Field']]); - $field['display_binary_as_hex'] = true; - } else { - $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]); - } + if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) { + $vrow[$field['Field']] = bin2hex($vrow[$field['Field']]); + $field['display_binary_as_hex'] = true; + } else { + $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]); + } } // end if $special_chars = htmlspecialchars($vrow[$field['Field']]); - //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column - $special_chars_encoded = PMA_duplicateFirstNewline($special_chars); + //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column + $special_chars_encoded = PMA_duplicateFirstNewline($special_chars); $data = $vrow[$field['Field']]; } // end if... else... @@ -562,9 +562,9 @@ } // this is set only when appropriate and is always true - if (isset($field['display_binary_as_hex'])) { - $default_function = 'UNHEX'; - } + if (isset($field['display_binary_as_hex'])) { + $default_function = 'UNHEX'; + } // loop on the dropdown array and print all available options for that field. foreach ($dropdown as $each_dropdown){ @@ -834,7 +834,7 @@ class="textfield" || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) { echo "\n"; // for blobstreaming - if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db)) + if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db)) { echo ''; echo ' ' . __('Remove BLOB Repository Reference') . "
"; @@ -889,10 +889,9 @@ class="textfield" if ($is_upload && $field['is_blob']) { // check if field type is of longblob and if the table is PBMS enabled. - if (($field['pma_type'] == "longblob") && PMA_BS_IsTablePBMSEnabled($db_name, $tbl_name, $tbl_type)) - { - echo '
'; - echo ' ' . __('Upload to BLOB repository'); + if (($field['pma_type'] == "longblob") && PMA_BS_IsTablePBMSEnabled($db_name, $tbl_name, $tbl_type)) { + echo '
'; + echo ' ' . __('Upload to BLOB repository'); } echo '
';