aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/docs/events.md16
-rw-r--r--phpBB/includes/acp/acp_profile.php145
-rw-r--r--phpBB/includes/functions_upload.php7
-rw-r--r--phpBB/phpbb/mimetype/guesser.php39
-rw-r--r--phpBB/phpbb/path_helper.php24
-rw-r--r--phpBB/styles/prosilver/template/posting_pm_header.html2
-rw-r--r--phpBB/styles/subsilver2/template/ucp_header.html2
-rw-r--r--tests/functional/fileupload_form_test.php4
-rw-r--r--tests/mimetype/guesser_test.php21
-rw-r--r--tests/path_helper/path_helper_test.php27
10 files changed, 132 insertions, 155 deletions
diff --git a/phpBB/docs/events.md b/phpBB/docs/events.md
index d0fd596913..e1308c71d1 100644
--- a/phpBB/docs/events.md
+++ b/phpBB/docs/events.md
@@ -764,6 +764,22 @@ posting_editor_subject_before
* Since: 3.1.0-a2
* Purpose: Add field (e.g. textbox) to the posting screen before the subject
+posting_pm_header_find_username_after
+===
+* Locations:
+ + styles/prosilver/template/posting_pm_header.html
+ + styles/subsilver2/template/ucp_header.html
+* Since: 3.1.0-RC4
+* Purpose: Add content after the find username link on composing pm
+
+posting_pm_header_find_username_before
+===
+* Locations:
+ + styles/prosilver/template/posting_pm_header.html
+ + styles/subsilver2/template/ucp_header.html
+* Since: 3.1.0-RC4
+* Purpose: Add content before the find username link on composing pm
+
quickreply_editor_panel_after
===
* Locations:
diff --git a/phpBB/includes/acp/acp_profile.php b/phpBB/includes/acp/acp_profile.php
index fda6ef25ec..046281596c 100644
--- a/phpBB/includes/acp/acp_profile.php
+++ b/phpBB/includes/acp/acp_profile.php
@@ -112,58 +112,8 @@ class acp_profile
$db->sql_query('DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . " WHERE field_id = $field_id");
$db->sql_query('DELETE FROM ' . PROFILE_LANG_TABLE . " WHERE field_id = $field_id");
- switch ($db->get_sql_layer())
- {
- case 'sqlite':
- case 'sqlite3':
- $sql = "SELECT sql
- FROM sqlite_master
- WHERE type = 'table'
- AND name = '" . PROFILE_FIELDS_DATA_TABLE . "'
- ORDER BY type DESC, name;";
- $result = $db->sql_query($sql);
- $row = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
-
- // Create a temp table and populate it, destroy the existing one
- $db->sql_query(preg_replace('#CREATE\s+TABLE\s+"?' . PROFILE_FIELDS_DATA_TABLE . '"?#i', 'CREATE TEMPORARY TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp', $row['sql']));
- $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . '_temp SELECT * FROM ' . PROFILE_FIELDS_DATA_TABLE);
- $db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE);
-
- preg_match('#\((.*)\)#s', $row['sql'], $matches);
-
- $new_table_cols = trim($matches[1]);
- $old_table_cols = preg_split('/,(?=[\\sa-z])/im', $new_table_cols);
- $column_list = array();
-
- foreach ($old_table_cols as $declaration)
- {
- $entities = preg_split('#\s+#', trim($declaration));
-
- if ($entities[0] == 'PRIMARY')
- {
- continue;
- }
-
- if ($entities[0] !== 'pf_' . $field_ident)
- {
- $column_list[] = $entities[0];
- }
- }
-
- $columns = implode(',', $column_list);
-
- $new_table_cols = preg_replace('/' . 'pf_' . $field_ident . '[^,]+,/', '', $new_table_cols);
-
- // create a new table and fill it up. destroy the temp one
- $db->sql_query('CREATE TABLE ' . PROFILE_FIELDS_DATA_TABLE . ' (' . $new_table_cols . ');');
- $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . PROFILE_FIELDS_DATA_TABLE . '_temp;');
- $db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp');
- break;
-
- default:
- $db->sql_query('ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " DROP COLUMN pf_$field_ident");
- }
+ $db_tools = $phpbb_container->get('dbal.tools');
+ $db_tools->sql_column_remove(PROFILE_FIELDS_DATA_TABLE, 'pf_' . $field_ident);
$order = 0;
@@ -932,9 +882,7 @@ class acp_profile
$field_ident = 'pf_' . $field_ident;
$db_tools = $phpbb_container->get('dbal.tools');
-
- list($sql_type, $null) = $db_tools->get_column_type($profile_field->get_database_column_type());
- $profile_sql[] = $this->add_field_ident($field_ident, $sql_type);
+ $db_tools->sql_column_add(PROFILE_FIELDS_DATA_TABLE, $field_ident, array($profile_field->get_database_column_type(), null));
}
$sql_ary = array(
@@ -1188,91 +1136,4 @@ class acp_profile
}
}
}
-
- /**
- * Return sql statement for adding a new field ident (profile field) to the profile fields data table
- */
- function add_field_ident($field_ident, $sql_type)
- {
- global $db;
-
- switch ($db->get_sql_layer())
- {
- case 'mysql':
- case 'mysql4':
- case 'mysqli':
- $sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD `$field_ident` " . $sql_type;
-
- break;
-
- case 'sqlite':
- case 'sqlite3':
- if (version_compare($db->sql_server_info(true), '3.0') == -1)
- {
- $sql = "SELECT sql
- FROM sqlite_master
- WHERE type = 'table'
- AND name = '" . PROFILE_FIELDS_DATA_TABLE . "'
- ORDER BY type DESC, name;";
- $result = $db->sql_query($sql);
- $row = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
-
- // Create a temp table and populate it, destroy the existing one
- $db->sql_query(preg_replace('#CREATE\s+TABLE\s+"?' . PROFILE_FIELDS_DATA_TABLE . '"?#i', 'CREATE TEMPORARY TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp', $row['sql']));
- $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . '_temp SELECT * FROM ' . PROFILE_FIELDS_DATA_TABLE);
- $db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE);
-
- preg_match('#\((.*)\)#s', $row['sql'], $matches);
-
- $new_table_cols = trim($matches[1]);
- $old_table_cols = explode(',', $new_table_cols);
- $column_list = array();
-
- foreach ($old_table_cols as $declaration)
- {
- $entities = preg_split('#\s+#', trim($declaration));
- if ($entities[0] == 'PRIMARY')
- {
- continue;
- }
- $column_list[] = $entities[0];
- }
-
- $columns = implode(',', $column_list);
-
- $new_table_cols = $field_ident . ' ' . $sql_type . ',' . $new_table_cols;
-
- // create a new table and fill it up. destroy the temp one
- $db->sql_query('CREATE TABLE ' . PROFILE_FIELDS_DATA_TABLE . ' (' . $new_table_cols . ');');
- $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . PROFILE_FIELDS_DATA_TABLE . '_temp;');
- $db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp');
- }
- else
- {
- $sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD $field_ident [$sql_type]";
- }
-
- break;
-
- case 'mssql':
- case 'mssql_odbc':
- case 'mssqlnative':
- $sql = 'ALTER TABLE [' . PROFILE_FIELDS_DATA_TABLE . "] ADD [$field_ident] " . $sql_type;
-
- break;
-
- case 'postgres':
- $sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD COLUMN \"$field_ident\" " . $sql_type;
-
- break;
-
- case 'oracle':
- $sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD $field_ident " . $sql_type;
-
- break;
- }
-
- return $sql;
- }
}
diff --git a/phpBB/includes/functions_upload.php b/phpBB/includes/functions_upload.php
index a0a67ccf3d..f179b2fd70 100644
--- a/phpBB/includes/functions_upload.php
+++ b/phpBB/includes/functions_upload.php
@@ -232,7 +232,12 @@ class filespec
{
if ($this->mimetype_guesser !== null)
{
- $this->mimetype = $this->mimetype_guesser->guess($filename);
+ $mimetype = $this->mimetype_guesser->guess($filename, $this->uploadname);
+
+ if ($mimetype !== 'application/octet-stream')
+ {
+ $this->mimetype = $mimetype;
+ }
}
return $this->mimetype;
diff --git a/phpBB/phpbb/mimetype/guesser.php b/phpBB/phpbb/mimetype/guesser.php
index 773a1f822a..8baa77089b 100644
--- a/phpBB/phpbb/mimetype/guesser.php
+++ b/phpBB/phpbb/mimetype/guesser.php
@@ -115,17 +115,42 @@ class guesser
return false;
}
+ $mimetype = 'application/octet-stream';
+
foreach ($this->guessers as $guesser)
{
- $mimetype = $guesser->guess($file, $file_name);
+ $mimetype_guess = $guesser->guess($file, $file_name);
- // Try to guess something that is not the fallback application/octet-stream
- if ($mimetype !== null && $mimetype !== 'application/octet-stream')
- {
- return $mimetype;
- }
+ $mimetype = $this->choose_mime_type($mimetype, $mimetype_guess);
}
// Return any mimetype if we got a result or the fallback value
- return (!empty($mimetype)) ? $mimetype : 'application/octet-stream';
+ return $mimetype;
+ }
+
+ /**
+ * Choose the best mime type based on the current mime type and the guess
+ * If a guesser returns nulls or application/octet-stream, we will keep
+ * the current guess. Guesses with a slash inside them will be favored over
+ * already existing ones. However, any guess that will pass the first check
+ * will always overwrite the default application/octet-stream.
+ *
+ * @param string $mime_type The current mime type
+ * @param string $guess The current mime type guess
+ *
+ * @return string The best mime type based on current mime type and guess
+ */
+ public function choose_mime_type($mime_type, $guess)
+ {
+ if ($guess === null || $guess == 'application/octet-stream')
+ {
+ return $mime_type;
+ }
+
+ if ($mime_type == 'application/octet-stream' || strpos($guess, '/') !== false)
+ {
+ $mime_type = $guess;
+ }
+
+ return $mime_type;
}
}
diff --git a/phpBB/phpbb/path_helper.php b/phpBB/phpbb/path_helper.php
index 38dbbab51e..936564d8b6 100644
--- a/phpBB/phpbb/path_helper.php
+++ b/phpBB/phpbb/path_helper.php
@@ -316,7 +316,7 @@ class path_helper
* Glue URL parameters together
*
* @param array $params URL parameters in the form of array(name => value)
- * @return string Returns the glued string, e.g. name1=value1&name2=value2
+ * @return string Returns the glued string, e.g. name1=value1&name2&name3=value3
*/
public function glue_url_params($params)
{
@@ -324,7 +324,15 @@ class path_helper
foreach ($params as $key => $value)
{
- $_params[] = $key . '=' . $value;
+ // some parameters do not have value
+ if ($value !== null)
+ {
+ $_params[] = $key . '=' . $value;
+ }
+ else
+ {
+ $_params[] = $key;
+ }
}
return implode('&', $_params);
}
@@ -353,7 +361,17 @@ class path_helper
{
continue;
}
- list($key, $value) = explode('=', $argument, 2);
+
+ // some parameters don't have value
+ if (strpos($argument, '=') !== false)
+ {
+ list($key, $value) = explode('=', $argument, 2);
+ }
+ else
+ {
+ $key = $argument;
+ $value = null;
+ }
if ($key === '')
{
diff --git a/phpBB/styles/prosilver/template/posting_pm_header.html b/phpBB/styles/prosilver/template/posting_pm_header.html
index dea50b5daf..032d8c6a6f 100644
--- a/phpBB/styles/prosilver/template/posting_pm_header.html
+++ b/phpBB/styles/prosilver/template/posting_pm_header.html
@@ -15,7 +15,9 @@
<dd class="recipients">
<input type="submit" name="add_to" value="{L_ADD}" class="button2" tabindex="1" />
<input type="submit" name="add_bcc" value="{L_ADD_BCC}" class="button2" tabindex="1" />
+ <!-- EVENT posting_pm_header_find_username_before -->
<span><a href="{U_FIND_USERNAME}" onclick="find_username(this.href); return false;">{L_FIND_USERNAME}</a></span>
+ <!-- EVENT posting_pm_header_find_username_after -->
</dd>
</dl>
<!-- ENDIF -->
diff --git a/phpBB/styles/subsilver2/template/ucp_header.html b/phpBB/styles/subsilver2/template/ucp_header.html
index e3aaef6943..dff2841b54 100644
--- a/phpBB/styles/subsilver2/template/ucp_header.html
+++ b/phpBB/styles/subsilver2/template/ucp_header.html
@@ -25,11 +25,13 @@
<tr>
<td class="row1"><b class="genmed">{L_USERNAMES}{L_COLON}</b></td>
</tr>
+ <!-- EVENT posting_pm_header_find_username_before -->
<tr>
<td class="row2"><textarea name="username_list" rows="5" cols="22" tabindex="1"></textarea><br />
[ <a href="{U_FIND_USERNAME}" onclick="find_username(this.href); return false;">{L_FIND_USERNAME}</a> ]
</td>
</tr>
+ <!-- EVENT posting_pm_header_find_username_after -->
<!-- ENDIF -->
<!-- IF S_GROUP_OPTIONS -->
<tr>
diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php
index e87953367f..b8c48389e0 100644
--- a/tests/functional/fileupload_form_test.php
+++ b/tests/functional/fileupload_form_test.php
@@ -107,9 +107,9 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case
$crawler = $this->upload_file('disallowed.jpg', 'image/jpeg');
- // Hitting the ATTACHED_IMAGE_NOT_IMAGE error means we passed the
+ // Hitting the UNABLE_GET_IMAGE_SIZE error means we passed the
// DISALLOWED_CONTENT check
- $this->assertContains($this->lang('ATTACHED_IMAGE_NOT_IMAGE'), $crawler->text());
+ $this->assertContainsLang('UNABLE_GET_IMAGE_SIZE', $crawler->text());
}
public function test_too_large()
diff --git a/tests/mimetype/guesser_test.php b/tests/mimetype/guesser_test.php
index b74a9f236e..fa53e6c8c4 100644
--- a/tests/mimetype/guesser_test.php
+++ b/tests/mimetype/guesser_test.php
@@ -206,4 +206,25 @@ class guesser_test extends \phpbb_test_case
$this->assertInstanceOf('\phpbb\mimetype\content_guesser', $guessers[0]);
$this->assertInstanceOf('\phpbb\mimetype\extension_guesser', $guessers[3]);
}
+
+ public function data_choose_mime_type()
+ {
+ return array(
+ array('application/octet-stream', 'application/octet-stream', null),
+ array('application/octet-stream', 'application/octet-stream', 'application/octet-stream'),
+ array('binary', 'application/octet-stream', 'binary'),
+ array('image/jpeg', 'application/octet-stream', 'image/jpeg'),
+ array('image/jpeg', 'binary', 'image/jpeg'),
+ array('image/jpeg', 'image/jpg', 'image/jpeg'),
+ array('image/jpeg', 'image/jpeg', 'binary'),
+ );
+ }
+
+ /**
+ * @dataProvider data_choose_mime_type
+ */
+ public function test_choose_mime_type($expected, $mime_type, $guess)
+ {
+ $this->assertSame($expected, $this->guesser->choose_mime_type($mime_type, $guess));
+ }
}
diff --git a/tests/path_helper/path_helper_test.php b/tests/path_helper/path_helper_test.php
index 27e94d6a07..3832307897 100644
--- a/tests/path_helper/path_helper_test.php
+++ b/tests/path_helper/path_helper_test.php
@@ -205,6 +205,18 @@ class phpbb_path_helper_test extends phpbb_test_case
array('test' => 'xyz', 'var' => 'value'),
'test=xyz&amp;var=value',
),
+ array(
+ array('test' => null),
+ 'test',
+ ),
+ array(
+ array('test' => null, 'var' => null),
+ 'test&amp;var',
+ ),
+ array(
+ array('test' => 'xyz', 'var' => null, 'bar' => 'value'),
+ 'test=xyz&amp;var&amp;bar=value',
+ ),
);
}
@@ -254,6 +266,21 @@ class phpbb_path_helper_test extends phpbb_test_case
true,
array('base' => 'mcp.php', 'params' => array('f' => '3')),
),
+ array(
+ 'index.php?ready',
+ false,
+ array('base' => 'index.php', 'params' => array('ready' => null)),
+ ),
+ array(
+ 'index.php?i=1&amp;ready',
+ true,
+ array('base' => 'index.php', 'params' => array('i' => '1', 'ready' => null)),
+ ),
+ array(
+ 'index.php?ready&i=1',
+ false,
+ array('base' => 'index.php', 'params' => array('ready' => null, 'i' => '1')),
+ ),
);
}