Skip to content

Commit

Permalink
Version 0.4.0
Browse files Browse the repository at this point in the history
This version comes with fixing bug which was causing badly parsing some chars when editing config.yml file and some second changes such as adding link to website of Pico and version of plugin.
  • Loading branch information
Nepose committed Jan 15, 2019
1 parent b86b19f commit ae4070f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 113 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
Pico Edit plugin
================
Plugin provides a small admin panel for editing page content and CMS configuration. Now plugin is on beta testing so please don't hesitate to let me know when some bug is on it.
Plugin provides a small admin panel for editing page content and CMS configuration.

Install
-------

1. Set chmod (permissions) to 777 / 766 recursively on config/ and content/ directories. On Windows servers set to read/write for anyone. (In practice 644 will also work on most hostings, but 777 may be recommended in some situations).
1. Set permissions of `config/` and `content/` directories to allow read/write (777 or 755 recommended).
2. Clone the Github repo into your 'plugins' directory (so you get a 'pico_edit' subdirectory) OR download source code from releases and put it into 'pico_edit' subdir on 'plugins' directory.
3. Open the config.php file on 'pico_edit' and insert your sha256 hashed password
4. Visit http://www.yoursite.com/pico_edit and login
3. Open your config.yml file on configuration and add following lines to it:
```
pico_edit_password: put here SHA256 hashed password
pico_edit_default_author: put here default author to add for YAML header when creating page
```
4. Visit https://www.yoursite.com/pico_edit and login

**Pay attention** if you are installing plugin on a fresh CMS, make sure that you have *config.yml* file and not *config.yml.template*. For well working Pico Edit requires existing configuration file.

About
-----
Expand All @@ -21,11 +27,7 @@ Pico Edit's features:
* Edit Pico's config.yml file.
* Some basic Git functions such as push, pull etc.

Add to your config.yml following line to set default author of new pages:

pico_edit_default_author: 'Here put author'

![Screenshot](https:/blocknotes/pico_edit/blob/master/screenshot.png)
![Screenshot](https:/Nepose/pico_edit/blob/master/screenshot.png)

Deny access to some files
-------------------------
Expand Down
11 changes: 0 additions & 11 deletions config.php

This file was deleted.

4 changes: 3 additions & 1 deletion editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<ul class="nav0">
<li><a href="#" data-url="conf" class="post page-options"><span class="icon-equalizer2 marg-r5" aria-hidden="true"></span><i>configuration file</i></a></li>
<li><a href="#" data-url="/404" class="post page-404"><span class="icon-file-empty marg-r5" aria-hidden="true"></span><i>404 page</i></a></li>
<li><a href="http://picocms.org"><span class="icon-download2 marg-r5" aria-hidden="true"></span><i>download templates and plugins</i></a></li>
<li><a href="https:/Nepose/pico_edit"><span class="icon-eye marg-r5" aria-hidden="true"></span><i>plugin version: {{ pico_edit_version }}</i></a></li>
<!-- <li><a href="checkupdates"><span class="icon-loop2 marg-r5" aria-hidden="true"></span><i>check for updates</i></a></li> -->
</ul>
<ul class="nav">
{% for page in pages %}
Expand All @@ -40,7 +43,6 @@
<div id="epiceditor"></div>

<script src="{{ base_url }}/plugins/pico_edit/libs/jquery-1.12.3.min.js"></script>
<!-- <script src="{{ base_url }}/plugins/pico_edit/top_up-1.7.2/top_up-min.js"></script> -->
<script src="{{ base_url }}/plugins/pico_edit/libs/epiceditor/js/epiceditor.min.js"></script>
<script>
$(document).ready(function() {
Expand Down
109 changes: 19 additions & 90 deletions pico_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
/**
* Backend plugin for Pico CMS
*
* @author Mattia Roccoberton
* @link http://blocknot.es
* @author Mattia Roccoberton, Nepose since v0.3.0
* @link https://github.com/Nepose/pico_edit
* @license http://opensource.org/licenses/MIT
* @version 0.3.0
* @edited Nepose
* @version 0.4.0
*/

final class Pico_Edit extends AbstractPicoPlugin {
Expand All @@ -19,6 +18,7 @@ final class Pico_Edit extends AbstractPicoPlugin {
private $plugin_path = '';
private $password = '';
private $url = 'pico_edit';
private $version = '0.4.0';

public function onPageRendering(Twig_Environment &$twig, array &$twig_vars, &$templateName)
{
Expand All @@ -38,7 +38,7 @@ public function onPageRendering(Twig_Environment &$twig, array &$twig_vars, &$te
// $twig_vars['autoescape'] = false;
$twig_editor->addFilter('var_dump', new Twig_Filter_Function('var_dump'));
if( !$this->password ) {
$twig_vars['login_error'] = 'No password set for the backend.';
$twig_vars['login_error'] = 'No password set for the plugin. Edit please your configuration file.';
echo $twig_editor->render( 'login.html', $twig_vars ); // Render login.html
exit;
}
Expand All @@ -60,63 +60,23 @@ public function onPageRendering(Twig_Environment &$twig, array &$twig_vars, &$te
}
}

$twig_vars['pico_edit_version'] = $this->version;
echo $twig_editor->render('editor.html', $twig_vars); // Render editor.html
exit; // Don't continue to render template

}
}

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() . '/config.yml';
if( !file_exists( $conf ) ) touch( $conf );
$data = filter_var( file_get_contents( $conf ), FILTER_SANITIZE_STRING );
foreach( preg_split( "/((\r?\n)|(\r\n?))/", $data ) as $line ) {
$line_ = trim( $line );
if( !empty( $line_ ) )
{
$pos = strpos( $line_, '=' );
if( $pos > 0 )
{
$key = trim( substr( $line, 0, $pos ) );
if( $key && $key[0] != '#' )
{
$value = trim( substr( $line, $pos + 1 ) );
// if( isset( $config[$key] ) )
$config[$key] = $value;
}
}
else
{
$pos = strpos( $line_, '!' );
if( $pos > 0 )
{
$key = trim( substr( $line, 0, $pos ) );
if( $key && $key[0] != '#' )
{
$value = trim( substr( $line, $pos + 1 ) );
// if( isset( $config[$key] ) )
$config[$key] = ( $value == '1' || $value == 'true' || $value == 'TRUE' || $value == 'yes' || $value == 'YES' || $value == 'on' || $value == 'ON' );
}
}
}
}
}

$this->plugin_path = dirname( __FILE__ );
if( file_exists( $this->plugin_path .'/config.php' ) ) {
global $backend_password;
global $backend_url;
include_once( $this->plugin_path .'/config.php' );
$this->password = $backend_password;
if (isset($backend_url)) {
$this->url = $backend_url;
}
}
$this->password = $config['pico_edit_password'];
// $this->username = $config['pico_edit_username'];
$page_404 = $this->getConfig('content_dir') . '/404.md';
if( !file_exists( $page_404 ) ) touch( $page_404 );
if( !file_exists( $page_404 ) ) {
touch( $page_404 );
$temp_404_content = "---\nTitle: Error 404\nRobots: none\n---\n# Error 404\n\nWhoops. Looks like this page doesn't exist.";
file_put_contents( $page_404, $temp_404_content);
}
}

// public function on404ContentLoading( &$file ) { var_dump( $file ); }
Expand Down Expand Up @@ -144,6 +104,7 @@ public function onRequestUrl( &$url ) {
if( $url == $this->url.'/git' ) $this->do_git();
if( $url == $this->url.'/pushpull' ) $this->do_pushpull();
if( $url == $this->url.'/clearcache' ) $this->do_clearcache();
// if( $url == $this->url.'/checkupdates' ) $this->is_update_checker = true;
}

/**
Expand Down Expand Up @@ -186,41 +147,9 @@ private function do_new()
}
$path .= '/' . $file . $this->getConfig( 'content_ext' );

// TODO: check this part

// // From the bottom of the $contentDir, look for format templates,
// // working upwards until we get to CONTENT_DIR
// $template = null;
// $workDir = $contentDir;
// while(strlen($workDir) >= strlen(CONTENT_DIR)) {
// // See if there's a format template here...?
// if(file_exists($workDir . 'format.templ')) {
// $template = strip_tags(substr($workDir . 'format.templ', strlen(CONTENT_DIR)));
// break;
// }
// // Now strip off the last bit of path from the $workDir
// $workDir = preg_replace('/[^\/]*\/$/', '', $workDir);
// }

// $file .= CONTENT_EXT;

// $content = null;
// if(!is_null($template)) {
// $loader = new Twig_Loader_Filesystem(CONTENT_DIR);
// $twig = new Twig_Environment($loader, array('cache' => null));
// $twig->addExtension(new Twig_Extension_Debug());
// $twig_vars = array(
// 'title' => $title,
// 'date' => date('j F Y'),
// 'time' => date('h:m:s'),
// 'author' => 'ralph',
// );
// $content = $twig->render($template, $twig_vars);
// }

$error = '';
// if( is_null( $content ) ) {
$content = "/*\nTitle: $name\nAuthor: " . ( $this->getConfig( 'pico_edit_default_author' ) ? $this->getConfig( 'pico_edit_default_author' ) : '' ) . "\nDate: ". date('j F Y') . "\n*/\n\n";
$content = "---\nTitle: $name\nAuthor: " . ( $this->getConfig( 'pico_edit_default_author' ) ? $this->getConfig( 'pico_edit_default_author' ) : '' ) . "\n---\n\n";
// }

if( file_exists( $path ) ) $error = 'Error: A post already exists with this title';
Expand Down Expand Up @@ -248,7 +177,7 @@ private function do_open() {
if( $file && file_exists( $file ) ) die( file_get_contents( $file ) );
else die( 'Error: Invalid file' );
}
else if( $this->getConfig( 'pico_edit_options' ) )
else
{
$conf = $this->getConfigDir() . '/config.yml';
if( file_exists( $conf ) ) die( file_get_contents( $conf ) );
Expand All @@ -273,10 +202,10 @@ private function do_save() {
'error' => $error
)));
}
else if( $this->getConfig( 'pico_edit_options' ) )
else
{
$conf = $this->getConfigDir() . '/config.yml';
$content = ( isset( $_POST['content'] ) && $_POST['content'] ) ? filter_var( $_POST['content'], FILTER_SANITIZE_STRING ) : '';
$content = ( isset( $_POST['content'] ) && $_POST['content'] ) ? $_POST['content'] : '';
$error = '';
if( strlen( $content ) !== file_put_contents( $conf, $content ) ) $error = 'Error: cant save changes';
die( json_encode( array( 'content' => $content, 'file' => $conf, 'error' => $error ) ) );
Expand Down
Binary file modified screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions styles.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*========================================*/
/* Pico Edit Plugin
/* By: Mattia Roccoberton
/* https:/blocknotes/pico_edit
/* By: Mattia Roccoberton and Nepose
/* https:/Nepose/pico_edit
/*========================================*/

@font-face {
Expand Down

0 comments on commit ae4070f

Please sign in to comment.