mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
[ticket/10620] Added enhanced quotes in topic review
Added support for enhanced quotes in topic_review's quote button. NOTE: the UI doesn't appear to be testable via PhantomJS. PHPBB3-10620
This commit is contained in:
parent
c934b8f150
commit
06936bda05
3 changed files with 59 additions and 3 deletions
|
@ -167,7 +167,7 @@ function attachInline(index, filename) {
|
|||
/**
|
||||
* Add quote text to message
|
||||
*/
|
||||
function addquote(post_id, username, l_wrote) {
|
||||
function addquote(post_id, username, l_wrote, attributes) {
|
||||
var message_name = 'message_' + post_id;
|
||||
var theSelection = '';
|
||||
var divarea = false;
|
||||
|
@ -213,7 +213,12 @@ function addquote(post_id, username, l_wrote) {
|
|||
|
||||
if (theSelection) {
|
||||
if (bbcodeEnabled) {
|
||||
insert_text('[quote="' + username + '"]' + theSelection + '[/quote]');
|
||||
if (typeof attributes === 'undefined')
|
||||
{
|
||||
attributes = {};
|
||||
}
|
||||
attributes.author = username;
|
||||
insert_text(generate_quote(theSelection, attributes));
|
||||
} else {
|
||||
insert_text(username + ' ' + l_wrote + ':' + '\n');
|
||||
var lines = split_lines(theSelection);
|
||||
|
@ -226,6 +231,55 @@ function addquote(post_id, username, l_wrote) {
|
|||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a quote block for given text
|
||||
*
|
||||
* Possible attributes:
|
||||
* - author: author's name (usually a username)
|
||||
* - post_id: post_id of the post being quoted
|
||||
* - user_id: user_id of the user being quoted
|
||||
* - time: timestamp of the original message
|
||||
*
|
||||
* @param {!string} text Quote's text
|
||||
* @param {!Object} attributes Quote's attributes
|
||||
* @return {!string} Quote block to be used in a new post/text
|
||||
*/
|
||||
function generate_quote(text, attributes)
|
||||
{
|
||||
var quote = '[quote';
|
||||
if ('author' in attributes)
|
||||
{
|
||||
// Add the author as the BBCode's default attribute
|
||||
quote += '=' + enquote(attributes.author);
|
||||
delete attributes.author;
|
||||
}
|
||||
for (var name in attributes)
|
||||
{
|
||||
var value = attributes[name];
|
||||
quote += ' ' + name + '=' + enquote(String(value));
|
||||
}
|
||||
quote += ']' + text + '[/quote]';
|
||||
|
||||
return quote;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return given string between quotes
|
||||
*
|
||||
* Will use either single- or double- quotes depending on whichever requires less escaping.
|
||||
* Quotes and backslashes are escaped with backslashes where necessary
|
||||
*
|
||||
* @param {!string} str Original string
|
||||
* @return {!string} Escaped string within quotes
|
||||
*/
|
||||
function enquote(str)
|
||||
{
|
||||
var singleQuoted = "'" + str.replace(/[\\']/g, '\\$&') + "'",
|
||||
doubleQuoted = '"' + str.replace(/[\\"]/g, '\\$&') + '"';
|
||||
|
||||
return (singleQuoted.length < doubleQuoted.length) ? singleQuoted : doubleQuoted;
|
||||
}
|
||||
|
||||
function split_lines(text) {
|
||||
var lines = text.split('\n');
|
||||
var splitLines = new Array();
|
||||
|
|
|
@ -1193,6 +1193,8 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id
|
|||
'MESSAGE' => $message,
|
||||
'DECODED_MESSAGE' => $decoded_message,
|
||||
'POST_ID' => $row['post_id'],
|
||||
'POST_TIME' => $row['post_time'],
|
||||
'USER_ID' => $row['user_id'],
|
||||
'U_MINI_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $row['post_id']) . '#p' . $row['post_id'],
|
||||
'U_MCP_DETAILS' => ($auth->acl_get('m_info', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&mode=post_details&f=' . $forum_id . '&p=' . $row['post_id'], true, $user->session_id) : '',
|
||||
'POSTER_QUOTE' => ($show_quote_button && $auth->acl_get('f_reply', $forum_id)) ? addslashes(get_username_string('username', $poster_id, $row['username'], $row['user_colour'], $row['post_username'])) : '',
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
<!-- ENDIF -->
|
||||
<!-- IF topic_review_row.POSTER_QUOTE and topic_review_row.DECODED_MESSAGE -->
|
||||
<li>
|
||||
<a href="#postingbox" onclick="addquote({topic_review_row.POST_ID}, '{topic_review_row.POSTER_QUOTE}', '{LA_WROTE}');" title="{L_QUOTE} {topic_review_row.POST_AUTHOR}" class="button icon-button quote-icon">
|
||||
<a href="#postingbox" onclick="addquote({topic_review_row.POST_ID}, '{topic_review_row.POSTER_QUOTE}', '{LA_WROTE}', {post_id:{topic_review_row.POST_ID},time:{topic_review_row.POST_TIME},user_id:{topic_review_row.USER_ID}});" title="{L_QUOTE} {topic_review_row.POST_AUTHOR}" class="button icon-button quote-icon">
|
||||
<span>{L_QUOTE} {topic_review_row.POST_AUTHOR}</span>
|
||||
</a>
|
||||
</li>
|
||||
|
|
Loading…
Add table
Reference in a new issue