Module: ProcessPreview
#1
Posted 31 December 2011 - 07:39 AM
here's a really simple preview module. It adds a "preview" button next to "save".
To use it you have to copy "preview.php" to your root folder. (If the module has write permission it should do it automatically).
Please let me now if it work and what do you think about it.
You can download it here: https://github.com/N...ProcessPreview/
Happy new year(!!!),
Nico
#2
Posted 31 December 2011 - 08:36 AM
How about cloning it to upper right area (like the save button and other buttons are cloned)?
I would also add "float: left" to #wrap_preview div in ProcessPreview.css so it would show before "Save page" button, it makes sense...
#3
Posted 31 December 2011 - 08:40 AM
To the second: I guess it's better like this, because "Save"/"Publish" is the main button and "Preview" is just a second, optional.
#4
Posted 31 December 2011 - 10:45 AM
1. This is another module that shouldn't be a 'Process' module the way it's currently implemented. But I think you may want to make this a real Process module for another reason (below). But if you stick with the preview.php method, then you likely want to make this a regular non-Process module and make it extend WireData rather than Process.
2. I'm concerned about the safety of preview.php. This gives any logged-in user access to view any page they want to. If you had to stick with this method, I would change it as follows:
<?php
include './index.php'; // add "./" before index.php to ensure it's not picking up another from PHP's path
if(!wire('user')->isLoggedin()) throw new Wire404Exception();
$page = wire('pages')->get((int) $_GET['id']); // typecast to (int)
if(!$page || !$page->id) throw new Wire404Exception(); // check that it exists
if(!$page->editable()) throw new WirePermissionException("You don't have access to edit that page"); // check for edit permission
foreach(wire('input')->get as $key => $value) { // change from $_GET to wire('input')->get
$key = wire('sanitizer')->name($key);
if($key != $_GET['key']) continue; // skip over invalid field name
if(!$page->fields->getField($key)) continue; // skip over field that this page doesn't have
$return->setFieldValue($key, $value, false); // add the extra 'false' for optimization: prevents PW from loading previous value
}
echo $return->setOutputFormatting(true)->render();
3. What may be a preferable way to implement this is to move everything from preview.php into an execute() function of your ProcessPreview.module. Then have ProcessPreview's install method add a page using the 'admin' template to /processwire/page/preview/ and assign ProcessPreview to the 'process' property of that page. See the install() method of this module for an example of how to do that: https://github.com/r...PagesCSV.module
The reason may be be a preferable way to do it is because it ensures that PW admin is still the gatekeeper to an admin activity. And it also removes the necessity for someone to have an extra php file that they might or might not have to copy to your site root. However, if you still prefer preview.php, I don't necessarily see a problem with using the preview.php if the security of it is updated like in the example above.
---
Edit: added 2 more lines in the foreach
#6
Posted 05 January 2012 - 06:40 PM
#7
Posted 06 January 2012 - 10:38 AM
#9
Posted 11 January 2012 - 04:20 AM
@somartist | modules created | support me, flattr my work flattr.com
#11
Posted 04 February 2012 - 05:38 AM
I get the following error:
Request-URI Too Large
Is it trying to pass the entire page body in a $_GET var? That's what it appears to be doing on my installation anyway
#12
Posted 04 February 2012 - 07:41 AM
/ Nico
#13
Posted 04 February 2012 - 09:39 AM
#15
Posted 07 April 2012 - 03:38 PM
Please let me introduce ProcessPreview 2.0.
The new version doesn't need the preview.php anymore because it works completely different. Just have a look in the code (only 89 lines!).
Also it now uses AJAX POST requests instead of the old GET way.
You can download it on GitHub: https://github.com/N...ProcessPreview/
Greets,
Nico
#16
Posted 07 April 2012 - 05:43 PM
For anyone confused as to what the new module does, it basically allows you to view the page as if it were published. In fact, for the current page it sets the status of the page as though it were published (I think) but only for the page launched by the preview button, and doesn't save that state, so you're viewing it as if it were published even though it isn't.
I think that's right anyway.
#17
Posted 07 April 2012 - 05:49 PM
Do you know that the "view" button of PW does actually same as this module? Any logged in user that can edit/view a page can also "view" it even if the page is unpublished. I didn't knew that for some time.
So this module could just add a target='_blank' attribute to the "view" tab and do the exactly same.
The other thing is: This module doesn't do what I expect from a "preview" module. I would assume that when I want to "preview" a page I'm editing, that it works without saving the page actually. I guess there would be the need to have a more complicated process going to get this work. I can't think of any atm. But I'm sure there is one.
After testing you module, there was an issue when I click preview, it opens new window. I close the window, and when I click "save" it open 1-2 Windows again with the preview. I close them and still the same. I need to reload the page to get saving to work.
@somartist | modules created | support me, flattr my work flattr.com
#18
Posted 07 April 2012 - 06:15 PM
Also will this approach work with when there's some logic happen in the template view to show something based on the pages id or childs?
@somartist | modules created | support me, flattr my work flattr.com
#19
Posted 08 April 2012 - 03:52 AM
#20
Posted 08 April 2012 - 03:56 AM
@somartist | modules created | support me, flattr my work flattr.com
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users













