Pico-Editor-Plugin
Pico-Editor-Plugin copied to clipboard
Error: Invalid file when opening any file for editing
It appears the basename() function does not provide the proper filename for the built-in pages that come with the Pico CMS (Welcome, Sub Page Index and Sub Page). This results in Invalid file errors when attempting to edit any of the pages. I am using wamp.
I am also facing the same problem. I think there should one more option for the file location and file name in New and Edit options.
Also experiencing this issue. I can edit files created by the editor, but when I try to edit pages created manually, I get "Error: Invalid file".
can not open already existing pages correctly
Error: Invalid file
Same error
Ideally look at some of the forks fixing it, there are couple of them floating around.
basename()
leaves only the last trailing part of the path so the file is always looked up in the root directory.
It looks like there are multiple causes for this error.
I'm looking into fixing them.
By the way, does any know if this project is maintained anymore? It doesn't seem like it. It's been 10 months since any activity, there are 8 pull requests waiting and no response to issues from the project owner. I'd be willing to take over, I'd probably have to fork and apply the pull requests manually.
It would be nice to have a working editor for pico.
Edit: I have some specific requests after working with Pico over night. Some are obvious, others are special requests
- Be able to edit a different file name compared to its title
- Create, edit and move documents from one directory to another
- Always have the "Save" button handy
- Some sort of preview akin to this: http://www.getuikit.com/docs/addons_markdownarea.html
- Front-end editor instead of a backend one as the backend defeats the purpose of pico
That's all I can think up at this time, I'm sure others have other requests for this plugin as well.
Is this fixed? Would be great to have this working.
If anyone is looking at this thread any more, this fixes this problem. Edit pico_editor.php.
if(!isset($_SESSION['pico_logged_in']) || !$_SESSION['pico_logged_in']) die(json_encode(array('error' => 'Error: Unathorized')));
$file_url = isset($_POST['file']) && $_POST['file'] ? $_POST['file'] : '';
/*
* This was rewritten from the GitHub, as basename() did not work
*/
$parts = parse_url($file_url);
$file = $parts['path']; // past the domain
if(!$file) die('Error: Invalid file');
// directories end in '/' and assume index, but that doesn't show in the POST value
if(substr($file, -1) == '/') {
$file .= 'index';
}
$file .= CONTENT_EXT;
// remove the initial '/' from the requested page before prepending CONTENT_DIR
$file = substr($file, 1);
if(file_exists(CONTENT_DIR . $file)) die(file_get_contents(CONTENT_DIR . $file));
else die('Error: Invalid file');
Hi Rory,
I'm a bit of a PHP noob, where do I edit this in the file? :)
Thanks
Sorry I should have mentioned that. This was the function do_open()
On Thu, Apr 2, 2015 at 9:56 AM, Wessel Grift [email protected] wrote:
Hi Rory,
I'm a bit of a PHP noob, where do I edit this in the file? :)
Thanks
— Reply to this email directly or view it on GitHub https://github.com/gilbitron/Pico-Editor-Plugin/issues/2#issuecomment-88956842 .
Thanks, but still getting Error: file invalid, unfortunately :*( I used it like this:
if(!isset($_SESSION['pico_logged_in']) || !$_SESSION['pico_logged_in']) die(json_encode(array('error' => 'Error: Unathorized')));
$file_url = isset($_POST['file']) && $_POST['file'] ? $_POST['file'] : '';
/*
* This was rewritten from the GitHub, as basename() did not work
*/
$parts = parse_url($file_url);
$file = $parts['path']; // past the domain
if(!$file) die('Error: Invalid file');
// directories end in '/' and assume index, but that doesn't show in the POST value
if(substr($file, -1) == '/') {
$file .= 'index';
}
$file .= CONTENT_EXT;
// remove the initial '/' from the requested page before prepending CONTENT_DIR
$file = substr($file, 1);
if(file_exists(CONTENT_DIR . $file)) die(file_get_contents(CONTENT_DIR . $file));
else die('Error: Invalid file');
The best thing you can do is debug, or if you don't have that capacity, then add some lines in there like:
$parts = parse_url($file_url);
die(var_dump($parts));
And before the final if statement $file = substr($file, 1); die($file);
Those messages will show up right in the editor area. Make sure to check them one at a time, because it will stop at the "die" statement, and the first one will keep you from seeing the second one.
Alright, thanks:) I'll give it a try!
Me and my collegue made a dirty fix:
$file = str_replace('pico/', '', $file);
now the basename works :)
somehow it did: localhost/pico/content/pico/index.md
I"m glad that worked for you, but keep in mind that is specific to your implementation. It's better to have an agnostic solution that doesn't depend on a specific folder name or specific domain name (like "pico").
On Fri, Apr 3, 2015 at 12:20 PM, Wessel Grift [email protected] wrote:
Me and my collegue made a dirty fix:
$file = str_replace('pico/', '', $file);
now the basename works :)
— Reply to this email directly or view it on GitHub https://github.com/gilbitron/Pico-Editor-Plugin/issues/2#issuecomment-89379966 .
Indeed :) I hope someone will come along for a more permanent fix.
This is my quick fix for this issue, replace your do_open, do_save and do_delete functions in plugins/pico_editor/pico_editor.php with this gist: https://gist.github.com/tranduyhung/09ad558cb0a53b5f6be2
Please try this code on a test site. Although it works for me but it could erase your content or delete your file if it has a bug hidden somewhere.