1
#1
Inline Post Preview
Posted November 7th 2012, 5:54pm
The following modification will change the way post preview works in the "full" editor. Instead of being forced to constantly scroll to look at a previewed post, the previewed post will appear in a window inside the editor itself! It is the same "full" editor post preview which is used on this board.

This modification is only for Prosilver-based themes. If you use a subsilver2-based style, please consider moving into the 21st Century and upgrading to a Prosilver-based style.

This modification makes extensive changes to the posting_editor.html template. If you have installed a style and/or MOD which has altered this template, the manual installation procedure described below may not work. In that case, I would suggest that you contact the author of the style/MOD and ask them what needs to be changed in their style/MOD in order to make the necessary changes to enable inline post previews.

This modification requires jQuery. If you have not installed jQuery, the next post contains instructions for installing it.

OK...now that I have taken care of the fine-print, let's get to the modification!

Please log in to view this content.
dd_preview.zip
5.7 KiB  |  Downloaded 432 times
φ
Posts: 1599
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
1
#2
Inline Post Preview
Posted November 7th 2012, 11:50pm
The AJAX Inline Preview feature requires that you have jQuery installed.

If you installed the phpBB AJAX feature, you have already installed jQuery.

Do not copy the jQuery files to your own site! Google has generously made the jQuery files available on one of their blazing-fast edge cache servers, and loading jQuery from one of those servers will be an order of magnitude faster than loading it from your site.

If you have not already installed jQuery, here is how to do it. Open the overall_header.html template file and find the following line:

<script type="text/javascript" src="{T_SUPER_TEMPLATE_PATH}/forum_fn.js"></script>

Add the following line immediately above it:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>

Now save the file and clear the template cache, and jQuery will now be installed. Please note that this is not the most recent version of jQuery -- recent versions have become bloated and can cause your board to slow down.
φ
Posts: 1599
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
Inline Post Preview
Posted November 10th 2012, 4:08pm
Thanks for posting this Dion! I just installed it on my forum. I had to make a few small changes to it because of the text editor MOD that I have installed, but now that those changes are made, it works wonderfully, but I do not see the "loading bar" when the post is loading. I am not sure why, but perhaps you do?
φ
Posts: 280
Joined: October 2nd 2011, 11:00pm
Likes Given: 27
Likes Received: 4
Inline Post Preview
Posted November 11th 2012, 12:50am
Perhaps you removed the progress bar image from the admin folder, or perhaps your installation is slightly different than default. Maybe you made a transcription error when you did the changes. I'm not sure what else to tell you...
φ
Posts: 1599
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
Inline Post Preview
Posted November 11th 2012, 2:12pm
When I downloaded the attached .zip file, and extracted it, the extraction came out as corrupt, but the PHP file was there, so maybe there is something that I was supposed to upload that I did not get?
φ
Posts: 280
Joined: October 2nd 2011, 11:00pm
Likes Given: 27
Likes Received: 4
Inline Post Preview
Posted November 11th 2012, 2:47pm
David B said:
When I downloaded the attached .zip file, and extracted it, the extraction came out as corrupt, but the PHP file was there, so maybe there is something that I was supposed to upload that I did not get?

Thank you for pointing out the problem with the ZIP file. I just tried un-ZIPping it on a desktop system and the posting_editor.html file was corrupted. I have uploaded a new ZIP file.

φ
Posts: 1599
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
Inline Post Preview
Posted February 9th 2013, 2:13pm
I am sorry, but when I try to use the newly bundled posting_editor.html file, the progress bar appears, with the editing background in place, but it never completes the loading, and just shows the progress bar. When I manually enter the posting_editor.html code provided in your post above, the Preview button does not work at all.
φ
Posts: 280
Joined: October 2nd 2011, 11:00pm
Likes Given: 27
Likes Received: 4
Inline Post Preview
Posted February 10th 2013, 2:02pm
From the first post:

This modification makes extensive changes to the posting_editor.html template. If you have installed a style and/or MOD which has altered this template, the manual installation procedure described below may not work. In that case, I would suggest that you contact the author of the style/MOD and ask them what needs to be changed in their style/MOD in order to make the necessary changes to enable inline post previews.

Have you made any other changes to the posting_editor.html template?

It would also help if you provided more information than "does not work at all". When you load the posting page, check your error console for javascript errors. Do the same when you click the Preview button. If you're getting errors, please post them here.
φ
Posts: 1599
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
Inline Post Preview
Posted February 20th 2016, 2:00pm
I'm trying to port this to phpBB 3.1, but no matter what, I cannot get it working.
φ
Posts: 280
Joined: October 2nd 2011, 11:00pm
Likes Given: 27
Likes Received: 4
Inline Post Preview
Posted February 21st 2016, 1:10am
It's good to see you here!

The biggest issues with porting this hack to phpBB 3.1 are that the the template variable names have changed slightly, onload_functions() function no longer exists, and jQuery is loaded differently.

If you adjust the code for the 3.1 template variable names, remove the onload_functions() stuff, and allow phpBB 3.1 to load jQuery, you should be fine.
φ
Posts: 1599
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
Inline Post Preview
Posted February 21st 2016, 6:29pm
Dion said:
It's good to see you here!

It's good to be back!

Dion said:
The biggest issues with porting this hack to phpBB 3.1 are that the the template variable names have changed slightly, onload_functions() function no longer exists, and jQuery is loaded differently.

If you adjust the code for the 3.1 template variable names, remove the onload_functions() stuff, and allow phpBB 3.1 to load jQuery, you should be fine.

Very well, thank you.
φ
Posts: 280
Joined: October 2nd 2011, 11:00pm
Likes Given: 27
Likes Received: 4
Inline Post Preview
Posted August 9th 2017, 10:06am
For anyone looking to use this on phpBB 3.2, I can confirm that it works as long as you strip out the `onload_functions()` stuff as Dion said. It is not necessary for changes to be made to the template variables, as they seem to be working even though they did not in 3.1.
φ
Posts: 280
Joined: October 2nd 2011, 11:00pm
Likes Given: 27
Likes Received: 4
Inline Post Preview
Posted August 9th 2017, 3:51pm
I am not sure how big of an issue this is, but for some reason, attachments on my forum with the ".7z" extension display the following message when in preview mode: "[The extension 7z has been deactivated and can no longer be displayed.]" I have not disabled 7z extensions on my forum, so I am not sure why this is happening, nor am I sure if this was an issue on phpBB 3.0. I also do not know if this happens with other file extension types as well, but I would imagine that it likely does.
φ
Posts: 280
Joined: October 2nd 2011, 11:00pm
Likes Given: 27
Likes Received: 4
Inline Post Preview
Posted August 9th 2017, 4:44pm
I believe that is an issue with the ddpreview.php file not being compatible with phpBB 3.2. The message parser was completely rewritten in phpBB 3.2 and a number of its options changed.

I suspect that you can ignore the message and the post will be saved correctly. Alternately, you can edit the ddpreview.php file and update it to be compatible with the message parser in phpBB 3.2. It's a small file so it should be pretty easy to do.
φ
Posts: 1599
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
Inline Post Preview
Posted August 9th 2017, 9:33pm
Yeah, I will look into doing that later on. The message does not effect the final post, but it would be nice to correct. Another issue that I ran into was that on 3.2, the "Submit" button wasn't working. The solution was to replace this section of the modified code...

<input type="submit" data-ajax="postform" data-form="{S_POST_ACTION}" accesskey="s" tabindex="6" name="post" value="{L_SUBMIT}" class="button1 default-submit-action" /> 


...with this:

<input type="submit" accesskey="s" tabindex="6" name="post" value="{L_SUBMIT}" class="button1 default-submit-action" /> 


There were also some really strange formatting issues, but toying with the CSS a bit was an easy fix for the problem.
φ
Posts: 280
Joined: October 2nd 2011, 11:00pm
Likes Given: 27
Likes Received: 4
Inline Post Preview
Posted September 14th 2017, 7:15am
Dion said:
I believe that is an issue with the ddpreview.php file not being compatible with phpBB 3.2. The message parser was completely rewritten in phpBB 3.2 and a number of its options changed.
I've started working on trying to fix the problem, and I haven't made any progress so far. I figured a good place to start would be to look at the phpBB message parser file. One of the functions that I found inside was this:

	function prepare_bbcodes()
{
// Ok, seems like users instead want the no-parsing of urls, smilies, etc. after and before and within quote tags being tagged as "not a bug".
// Fine by me ;) Will ease our live... but do not come back and cry at us, we won't hear you.

/* Add newline at the end and in front of each quote block to prevent parsing errors (urls, smilies, etc.)
if (strpos($this->message, '[quote') !== false && strpos($this->message, '[/quote]') !== false)
{
$this->message = str_replace("\r\n", "\n", $this->message);

// We strip newlines and spaces after and before quotes in quotes (trimming) and then add exactly one newline
$this->message = preg_replace('#\[quote(=".*?")?\]\s*(.*?)\s*\[/quote\]#siu', '[quote\1]' . "\n" . '\2' ."\n[/quote]", $this->message);
}
*/

// Add other checks which needs to be placed before actually parsing anything (be it bbcodes, smilies, urls...)
}


Why is there an entire function commented out with a snarky comment in the phpBB 3.2 source?

Update: I found the new parse attachments function.

	function parse_attachments($form_name, $mode, $forum_id, $submit, $preview, $refresh, $is_message = false)
{
global $config, $auth, $user, $phpbb_root_path, $phpEx, $db, $request;
global $phpbb_container;

$error = array();

$num_attachments = sizeof($this->attachment_data);
$this->filename_data['filecomment'] = $request->variable('filecomment', '', true);
$upload = $request->file($form_name);
$upload_file = (!empty($upload) && $upload['name'] !== 'none' && trim($upload['name']));

$add_file = (isset($_POST['add_file'])) ? true : false;
$delete_file = (isset($_POST['delete_file'])) ? true : false;

// First of all adjust comments if changed
$actual_comment_list = $request->variable('comment_list', array(''), true);

foreach ($actual_comment_list as $comment_key => $comment)
{
if (!isset($this->attachment_data[$comment_key]))
{
continue;
}

if ($this->attachment_data[$comment_key]['attach_comment'] != $actual_comment_list[$comment_key])
{
$this->attachment_data[$comment_key]['attach_comment'] = $actual_comment_list[$comment_key];
}
}

$cfg = array();
$cfg['max_attachments'] = ($is_message) ? $config['max_attachments_pm'] : $config['max_attachments'];
$forum_id = ($is_message) ? 0 : $forum_id;

if ($submit && in_array($mode, array('post', 'reply', 'quote', 'edit')) && $upload_file)
{
if ($num_attachments < $cfg['max_attachments'] || $auth->acl_get('a_') || $auth->acl_get('m_', $forum_id))
{
/** @var \phpbb\attachment\manager $attachment_manager */
$attachment_manager = $phpbb_container->get('attachment.manager');
$filedata = $attachment_manager->upload($form_name, $forum_id, false, '', $is_message);
$error = $filedata['error'];

if ($filedata['post_attach'] && !sizeof($error))
{
$sql_ary = array(
'physical_filename' => $filedata['physical_filename'],
'attach_comment' => $this->filename_data['filecomment'],
'real_filename' => $filedata['real_filename'],
'extension' => $filedata['extension'],
'mimetype' => $filedata['mimetype'],
'filesize' => $filedata['filesize'],
'filetime' => $filedata['filetime'],
'thumbnail' => $filedata['thumbnail'],
'is_orphan' => 1,
'in_message' => ($is_message) ? 1 : 0,
'poster_id' => $user->data['user_id'],
);

$db->sql_query('INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));

$new_entry = array(
'attach_id' => $db->sql_nextid(),
'is_orphan' => 1,
'real_filename' => $filedata['real_filename'],
'attach_comment'=> $this->filename_data['filecomment'],
'filesize' => $filedata['filesize'],
);

$this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data);
$this->message = preg_replace_callback('#\[attachment=([0-9]+)\](.*?)\[\/attachment\]#', function ($match) {
return '[attachment='.($match[1] + 1).']' . $match[2] . '[/attachment]';
}, $this->message);

$this->filename_data['filecomment'] = '';

// This Variable is set to false here, because Attachments are entered into the
// Database in two modes, one if the id_list is 0 and the second one if post_attach is true
// Since post_attach is automatically switched to true if an Attachment got added to the filesystem,
// but we are assigning an id of 0 here, we have to reset the post_attach variable to false.
//
// This is very relevant, because it could happen that the post got not submitted, but we do not
// know this circumstance here. We could be at the posting page or we could be redirected to the entered
// post. :)
$filedata['post_attach'] = false;
}
}
else
{
$error[] = $user->lang('TOO_MANY_ATTACHMENTS', (int) $cfg['max_attachments']);
}
}

if ($preview || $refresh || sizeof($error))
{
if (isset($this->plupload) && $this->plupload->is_active())
{
$json_response = new \phpbb\json_response();
}

// Perform actions on temporary attachments
if ($delete_file)
{
include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);

$index = array_keys($request->variable('delete_file', array(0 => 0)));
$index = (!empty($index)) ? $index[0] : false;

if ($index !== false && !empty($this->attachment_data[$index]))
{
/** @var \phpbb\attachment\manager $attachment_manager */
$attachment_manager = $phpbb_container->get('attachment.manager');

// delete selected attachment
if ($this->attachment_data[$index]['is_orphan'])
{
$sql = 'SELECT attach_id, physical_filename, thumbnail
FROM ' . ATTACHMENTS_TABLE . '
WHERE attach_id = ' . (int) $this->attachment_data[$index]['attach_id'] . '
AND is_orphan = 1
AND poster_id = ' . $user->data['user_id'];
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);

if ($row)
{
$attachment_manager->unlink($row['physical_filename'], 'file');

if ($row['thumbnail'])
{
$attachment_manager->unlink($row['physical_filename'], 'thumbnail');
}

$db->sql_query('DELETE FROM ' . ATTACHMENTS_TABLE . ' WHERE attach_id = ' . (int) $this->attachment_data[$index]['attach_id']);
}
}
else
{
$attachment_manager->delete('attach', $this->attachment_data[$index]['attach_id']);
}

unset($this->attachment_data[$index]);
$this->message = preg_replace_callback('#\[attachment=([0-9]+)\](.*?)\[\/attachment\]#', function ($match) use($index) {
return ($match[1] == $index) ? '' : (($match[1] > $index) ? '[attachment=' . ($match[1] - 1) . ']' . $match[2] . '[/attachment]' : $match[0]);
}, $this->message);

// Reindex Array
$this->attachment_data = array_values($this->attachment_data);
if (isset($this->plupload) && $this->plupload->is_active())
{
$json_response->send($this->attachment_data);
}
}
}
else if (($add_file || $preview) && $upload_file)
{
if ($num_attachments < $cfg['max_attachments'] || $auth->acl_gets('m_', 'a_', $forum_id))
{
/** @var \phpbb\attachment\manager $attachment_manager */
$attachment_manager = $phpbb_container->get('attachment.manager');
$filedata = $attachment_manager->upload($form_name, $forum_id, false, '', $is_message);
$error = array_merge($error, $filedata['error']);

if (!sizeof($error))
{
$sql_ary = array(
'physical_filename' => $filedata['physical_filename'],
'attach_comment' => $this->filename_data['filecomment'],
'real_filename' => $filedata['real_filename'],
'extension' => $filedata['extension'],
'mimetype' => $filedata['mimetype'],
'filesize' => $filedata['filesize'],
'filetime' => $filedata['filetime'],
'thumbnail' => $filedata['thumbnail'],
'is_orphan' => 1,
'in_message' => ($is_message) ? 1 : 0,
'poster_id' => $user->data['user_id'],
);

$db->sql_query('INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));

$new_entry = array(
'attach_id' => $db->sql_nextid(),
'is_orphan' => 1,
'real_filename' => $filedata['real_filename'],
'attach_comment'=> $this->filename_data['filecomment'],
'filesize' => $filedata['filesize'],
);

$this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data);
$this->message = preg_replace_callback('#\[attachment=([0-9]+)\](.*?)\[\/attachment\]#', function ($match) {
return '[attachment=' . ($match[1] + 1) . ']' . $match[2] . '[/attachment]';
}, $this->message);
$this->filename_data['filecomment'] = '';

if (isset($this->plupload) && $this->plupload->is_active())
{
$download_url = append_sid("{$phpbb_root_path}download/file.{$phpEx}", 'mode=view&id=' . $new_entry['attach_id']);

// Send the client the attachment data to maintain state
$json_response->send(array('data' => $this->attachment_data, 'download_url' => $download_url));
}
}
}
else
{
$error[] = $user->lang('TOO_MANY_ATTACHMENTS', (int) $cfg['max_attachments']);
}

if (!empty($error) && isset($this->plupload) && $this->plupload->is_active())
{
// If this is a plupload (and thus ajax) request, give the
// client the first error we have
$json_response->send(array(
'jsonrpc' => '2.0',
'id' => 'id',
'error' => array(
'code' => 105,
'message' => current($error),
),
));
}
}
}

foreach ($error as $error_msg)
{
$this->warn_msg[] = $error_msg;
}
}
φ
Posts: 280
Joined: October 2nd 2011, 11:00pm
Likes Given: 27
Likes Received: 4
Post a reply
16 posts

Who is online

Users browsing this forum: No registered users and 1 guest