Skip to content
This repository has been archived by the owner on May 21, 2021. It is now read-only.

Commit

Permalink
Added Pico options to allow/disallow to edit 404/options
Browse files Browse the repository at this point in the history
  • Loading branch information
blocknotes committed Apr 10, 2016
1 parent 4f4967f commit ffc3ccf
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 49 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,19 @@ Features:

* Simple and clean interface

* MarkDown preview (with top right icon in the editor)
* Page create/edit/delete

* Markdown preview (top right icon in the editor)

* Edit 404 page (aka "page not found")

* Edit Pico options

Options (Pico "config/config.php"):

$config['pico_edit_404'] = true;
$config['pico_edit_options'] = false; // Disallow options editing

Editing Pico options
--------------------

Expand Down
4 changes: 4 additions & 0 deletions editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
<a href="{{ base_url }}/pico_edit/logout" class="logout btn icon-switch" title="Logout"></a>
</div>
<ul class="nav0">
{% if config.pico_edit_options %}
<li><a href="#" data-url="conf" class="post page-options"><span class="icon-equalizer2 marg-r5" aria-hidden="true"></span><i>config options</i></a></li>
{% endif %}
{% if config.pico_edit_404 %}
<li><a href="#" data-url="{{ base_url }}/404" class="post page-404"><span class="icon-file-empty marg-r5" aria-hidden="true"></span><i>404</i></a></li>
{% endif %}
</ul>
<ul class="nav">
{% for page in pages %}
Expand Down
97 changes: 49 additions & 48 deletions pico_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ final class Pico_Edit extends AbstractPicoPlugin {
private $password = '';

public function onConfigLoaded( array &$config ) {
// Default options
if( !isset( $config['pico_edit_404'] ) ) $config['pico_edit_404'] = TRUE;
if( !isset( $config['pico_edit_options'] ) ) $config['pico_edit_options'] = TRUE;
// Parse extra options
$conf = $this->getConfigDir() . '/options.conf';
if( !file_exists( $conf ) ) touch( $conf );
Expand Down Expand Up @@ -245,57 +248,55 @@ private function do_new()
)));
}

private function do_open()
{
if(!isset($_SESSION['backend_logged_in']) || !$_SESSION['backend_logged_in']) die(json_encode(array('error' => 'Error: Unathorized')));
$file_url = isset($_POST['file']) && $_POST['file'] ? $_POST['file'] : '';
if( $file_url != 'conf' )
{
$file = self::get_real_filename($file_url);
if(!$file) die('Error: Invalid file');
private function do_open() {
if(!isset($_SESSION['backend_logged_in']) || !$_SESSION['backend_logged_in']) die(json_encode(array('error' => 'Error: Unathorized')));
$file_url = isset($_POST['file']) && $_POST['file'] ? $_POST['file'] : '';
if( $file_url != 'conf' )
{
$file = self::get_real_filename($file_url);
if(!$file) die('Error: Invalid file');

$file .= CONTENT_EXT;
if(file_exists(CONTENT_DIR . $file)) die(file_get_contents(CONTENT_DIR . $file));
else die('Error: Invalid file');
}
else
{
$conf = $this->getConfigDir() . '/options.conf';
if( file_exists( $conf ) ) die( file_get_contents( $conf ) );
else die( 'Error: Invalid file' );
}
$file .= CONTENT_EXT;
if(file_exists(CONTENT_DIR . $file)) die(file_get_contents(CONTENT_DIR . $file));
else die('Error: Invalid file');
}
else if( $this->getConfig( 'pico_edit_options' ) )
{
$conf = $this->getConfigDir() . '/options.conf';
if( file_exists( $conf ) ) die( file_get_contents( $conf ) );
else die( 'Error: Invalid file' );
}
}

private function do_save()
{
if(!isset($_SESSION['backend_logged_in']) || !$_SESSION['backend_logged_in']) die(json_encode(array('error' => 'Error: Unathorized')));
$file_url = isset($_POST['file']) && $_POST['file'] ? $_POST['file'] : '';
if( $file_url != 'conf' )
{
$file = self::get_real_filename($file_url);
if(!$file) die('Error: Invalid file');
$content = isset($_POST['content']) && $_POST['content'] ? $_POST['content'] : '';
if(!$content) die('Error: Invalid content');

$file .= CONTENT_EXT;
$error = '';
if(strlen($content) !== file_put_contents(CONTENT_DIR . $file, $content))
$error = 'Error: can not save changes ... ';

die(json_encode(array(
'content' => $content,
'file' => $file_url,
'error' => $error
)));
}
else
{
$conf = $this->getConfigDir() . '/options.conf';
$content = ( isset( $_POST['content'] ) && $_POST['content'] ) ? filter_var( $_POST['content'], FILTER_SANITIZE_STRING ) : '';
$error = '';
if( strlen( $content ) !== file_put_contents( $conf, $content ) ) $error = 'Error: can not save changes ... ';
die( json_encode( array( 'content' => $content, 'file' => $conf, 'error' => $error ) ) );
}
private function do_save() {
if(!isset($_SESSION['backend_logged_in']) || !$_SESSION['backend_logged_in']) die(json_encode(array('error' => 'Error: Unathorized')));
$file_url = isset($_POST['file']) && $_POST['file'] ? $_POST['file'] : '';
if( $file_url != 'conf' )
{
$file = self::get_real_filename($file_url);
if(!$file) die('Error: Invalid file');
$content = isset($_POST['content']) && $_POST['content'] ? $_POST['content'] : '';
if(!$content) die('Error: Invalid content');

$file .= CONTENT_EXT;
$error = '';
if(strlen($content) !== file_put_contents(CONTENT_DIR . $file, $content))
$error = 'Error: can not save changes ... ';

die(json_encode(array(
'content' => $content,
'file' => $file_url,
'error' => $error
)));
}
else if( $this->getConfig( 'pico_edit_options' ) )
{
$conf = $this->getConfigDir() . '/options.conf';
$content = ( isset( $_POST['content'] ) && $_POST['content'] ) ? filter_var( $_POST['content'], FILTER_SANITIZE_STRING ) : '';
$error = '';
if( strlen( $content ) !== file_put_contents( $conf, $content ) ) $error = 'Error: can not save changes ... ';
die( json_encode( array( 'content' => $content, 'file' => $conf, 'error' => $error ) ) );
}
}

private function do_delete() {
Expand Down

0 comments on commit ffc3ccf

Please sign in to comment.