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

Commit

Permalink
First release
Browse files Browse the repository at this point in the history
  • Loading branch information
blocknotes committed Apr 9, 2016
1 parent fff7f3b commit c7bf8e8
Show file tree
Hide file tree
Showing 35 changed files with 105 additions and 117 deletions.
9 changes: 9 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2016 Mattia Roccoberton

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15 changes: 8 additions & 7 deletions README.md
@@ -1,5 +1,5 @@
Peeked - A Web-Based Content Editor for Pico
============================================
Pico Back-end - An admin interface for Pico CMS
===============================================

Provides a Git-connected online Markdown editor and file manager for Pico.

Expand All @@ -8,30 +8,31 @@ Install

Either:

* Clone the Github repo into your 'plugins' directory (so you get a 'peeked' subdirectory)
* Clone the Github repo into your 'plugins' directory (so you get a 'cms' subdirectory)

Or:

* Extract the zip into your 'plugins' directory

Then:

1. Open the pico_editor_config.php file and insert your sha1 hashed password
2. Visit http://www.yoursite.com/peeked and login
1. Open the config.php file and insert your sha1 hashed password
2. Visit http://www.yoursite.com/cms and login
3. Update the permissions if needed.
4. Thats it :)

About
-----

Peeked provides an online, web browser based means to edit Pico page content. Additionally, it has the ability to perform some basic Git operations such as commit, push/pull etc.
Pico back-end provides an online, web browser based means to edit Pico page content. Additionally, it has the ability to perform some basic Git operations such as commit, push/pull etc.

The general use-case for Peeked is for one or more content editors to have a Git repo cloned onto their laptops. They can then go ahead and create or edit content, saving it to their local machine as required. When they're happy, they can commit to their local Git repo. How they publish the content is up to the administrator, but one method is to have a post-update hook on the Git server that publishes the content into the DocumentRoot of the webserver(s). Obviously, editors can Git-pull the changes other editors have made to their local machines so that they stay up to date. Depending on how you set things up, it's possible editors could even edit pages directly on the public website (and commit those to the Git repo from there).
The general use-case is for one or more content editors to have a Git repo cloned onto their laptops. They can then go ahead and create or edit content, saving it to their local machine as required. When they're happy, they can commit to their local Git repo. How they publish the content is up to the administrator, but one method is to have a post-update hook on the Git server that publishes the content into the DocumentRoot of the webserver(s). Obviously, editors can Git-pull the changes other editors have made to their local machines so that they stay up to date. Depending on how you set things up, it's possible editors could even edit pages directly on the public website (and commit those to the Git repo from there).

Git features are only shown in the editor UI if the server has a Git binary available, and the content is in a Git repo. Push/pull functions are only available if the repo has one or more remote servers configured into it.

History
-------

Pico Back-end is a fork + modifications of [Peeked](https://github.com/coofercat/peeked).
Peeked is a fork + modifications of the [Pico Editor](https://github.com/gilbitron/Pico-Editor-Plugin), written by [Gilbert Pellegrom](https://github.com/gilbitron). It contains a few bug fixes and some functional changes, most particularly the addition of some Git capabilities.

File renamed without changes.
100 changes: 50 additions & 50 deletions peeked.php → cms/backend.php
@@ -1,14 +1,14 @@
<?php

/**
* Editor plugin for Pico
* Backend plugin for Pico CMS
*
* @author Gilbert Pellegrom
* @link http://pico.dev7studios.com
* @author Mattia Roccoberton
* @link http://blocknot.es
* @license http://opensource.org/licenses/MIT
* @version 1.1
* @version 0.2
*/
class Peeked {

class Backend {

private $is_admin;
private $is_logout;
Expand All @@ -22,18 +22,18 @@ public function __construct()
$this->plugin_path = dirname(__FILE__);
$this->password = '';

if(file_exists($this->plugin_path .'/peeked_config.php')){
global $peeked_password;
include_once($this->plugin_path .'/peeked_config.php');
$this->password = $peeked_password;
if(file_exists($this->plugin_path .'/config.php')){
global $backend_password;
include_once($this->plugin_path .'/config.php');
$this->password = $backend_password;
}
}

public function request_url(&$url)
{
// If the request is anything to do with Peeked, then
// If the request is anything to do with backend, then
// we start the PHP session
if(substr($url, 0, 6) == 'peeked') {
if( substr( $url, 0, 3 ) == 'cms' ) {
if(function_exists('session_status')) {
if (session_status() == PHP_SESSION_NONE) {
session_start();
Expand All @@ -42,24 +42,24 @@ public function request_url(&$url)
session_start();
}
}
// Are we looking for /peeked?
if($url == 'peeked') $this->is_admin = true;
if($url == 'peeked/new') $this->do_new();
if($url == 'peeked/open') $this->do_open();
if($url == 'peeked/save') $this->do_save();
if($url == 'peeked/delete') $this->do_delete();
if($url == 'peeked/logout') $this->is_logout = true;
if($url == 'peeked/files') $this->do_filemgr();
if($url == 'peeked/commit') $this->do_commit();
if($url == 'peeked/git') $this->do_git();
if($url == 'peeked/pushpull') $this->do_pushpull();
// Are we looking for /cms?
if($url == 'cms') $this->is_admin = true;
if($url == 'cms/new') $this->do_new();
if($url == 'cms/open') $this->do_open();
if($url == 'cms/save') $this->do_save();
if($url == 'cms/delete') $this->do_delete();
if($url == 'cms/logout') $this->is_logout = true;
if($url == 'cms/files') $this->do_filemgr();
if($url == 'cms/commit') $this->do_commit();
if($url == 'cms/git') $this->do_git();
if($url == 'cms/pushpull') $this->do_pushpull();
}

public function before_render(&$twig_vars, &$twig)
{
if($this->is_logout){
session_destroy();
header('Location: '. $twig_vars['base_url'] .'/peeked');
header('Location: '. $twig_vars['base_url'] .'/cms');
exit;
}

Expand All @@ -68,16 +68,16 @@ public function before_render(&$twig_vars, &$twig)
$loader = new Twig_Loader_Filesystem($this->plugin_path);
$twig_editor = new Twig_Environment($loader, $twig_vars);
if(!$this->password){
$twig_vars['login_error'] = 'No password set for the Pico Editor.';
$twig_vars['login_error'] = 'No password set for the backend.';
echo $twig_editor->render('login.html', $twig_vars); // Render login.html
exit;
}

if(!isset($_SESSION['peeked_logged_in']) || !$_SESSION['peeked_logged_in']){
if(!isset($_SESSION['backend_logged_in']) || !$_SESSION['backend_logged_in']){
if(isset($_POST['password'])){
if(sha1($_POST['password']) == $this->password){
$_SESSION['peeked_logged_in'] = true;
$_SESSION['peeked_config'] = $twig_vars['config'];
$_SESSION['backend_logged_in'] = true;
$_SESSION['backend_config'] = $twig_vars['config'];
} else {
$twig_vars['login_error'] = 'Invalid password.';
echo $twig_editor->render('login.html', $twig_vars); // Render login.html
Expand All @@ -104,7 +104,7 @@ private static function get_real_filename($file_url)
{

$file_components = parse_url($file_url); // inner
$base_components = parse_url($_SESSION['peeked_config']['base_url']);
$base_components = parse_url($_SESSION['backend_config']['base_url']);
$file_path = rtrim($file_components['path'], '/');
$base_path = rtrim($base_components['path'], '/');

Expand All @@ -125,7 +125,7 @@ private static function get_real_filename($file_url)

private function do_new()
{
if(!isset($_SESSION['peeked_logged_in']) || !$_SESSION['peeked_logged_in']) die(json_encode(array('error' => 'Error: Unathorized')));
if(!isset($_SESSION['backend_logged_in']) || !$_SESSION['backend_logged_in']) die(json_encode(array('error' => 'Error: Unathorized')));
$title = isset($_POST['title']) && $_POST['title'] ? strip_tags($_POST['title']) : '';
$dir = isset($_POST['dir']) && $_POST['dir'] ? strip_tags($_POST['dir']) : '';
if(substr($dir,0,1) != '/') {
Expand Down Expand Up @@ -209,7 +209,7 @@ private function do_new()

private function do_open()
{
if(!isset($_SESSION['peeked_logged_in']) || !$_SESSION['peeked_logged_in']) die(json_encode(array('error' => 'Error: Unathorized')));
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'] : '';
$file = self::get_real_filename($file_url);
if(!$file) die('Error: Invalid file');
Expand All @@ -221,7 +221,7 @@ private function do_open()

private function do_save()
{
if(!isset($_SESSION['peeked_logged_in']) || !$_SESSION['peeked_logged_in']) die(json_encode(array('error' => 'Error: Unathorized')));
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'] : '';
$file = self::get_real_filename($file_url);
if(!$file) die('Error: Invalid file');
Expand All @@ -242,7 +242,7 @@ private function do_save()

private function do_delete()
{
if(!isset($_SESSION['peeked_logged_in']) || !$_SESSION['peeked_logged_in']) die(json_encode(array('error' => 'Error: Unathorized')));
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'] : '';
$file = self::get_real_filename($file_url);
if(!$file) die('Error: Invalid file');
Expand All @@ -253,7 +253,7 @@ private function do_delete()

private function do_filemgr()
{
if(!isset($_SESSION['peeked_logged_in']) || !$_SESSION['peeked_logged_in']) die(json_encode(array('error' => 'Error: Unathorized')));
if(!isset($_SESSION['backend_logged_in']) || !$_SESSION['backend_logged_in']) die(json_encode(array('error' => 'Error: Unathorized')));
$dir = isset($_POST['dir']) && $_POST['dir'] ? strip_tags($_POST['dir']) : '';
if(substr($dir,0,1) != '/') {
$dir = "/$dir";
Expand Down Expand Up @@ -281,7 +281,7 @@ private function do_filemgr()

private function do_commit()
{
if(!isset($_SESSION['peeked_logged_in']) || !$_SESSION['peeked_logged_in']) die(json_encode(array('error' => 'Error: Unathorized')));
if(!isset($_SESSION['backend_logged_in']) || !$_SESSION['backend_logged_in']) die(json_encode(array('error' => 'Error: Unathorized')));
if($_SERVER['REQUEST_METHOD'] == 'POST') {
return $this->do_commit_post();
}
Expand All @@ -290,7 +290,7 @@ private function do_commit()

private function do_commit_get()
{
if(file_exists('./plugins/peeked/commitform.html')) {
if(file_exists('./plugins/cms/commitform.html')) {
# Do the git stuff...
require_once 'Git-php-lib';
$repo = Git::open('.');
Expand All @@ -302,7 +302,7 @@ private function do_commit_get()
$status = array('Failed to run git-status: ' . $e->getMessage());
}

$loader = new Twig_Loader_Filesystem('./plugins/peeked');
$loader = new Twig_Loader_Filesystem('./plugins/cms');
$twig = new Twig_Environment($loader, array('cache' => null));
$twig->addExtension(new Twig_Extension_Debug());
$twig_vars = array(
Expand All @@ -311,7 +311,7 @@ private function do_commit_get()
$content = $twig->render('commitform.html', $twig_vars);
die($content);
} else {
die('Sorry, commitform.html was not found in the Peeked plugin. This is an installation problem.');
die('Sorry, commitform.html was not found in the backend plugin. This is an installation problem.');
}
}

Expand Down Expand Up @@ -340,7 +340,7 @@ private function do_commit_post()
}
}
}

$add_output = '';
if(count($to_add) > 0) {
try {
Expand Down Expand Up @@ -370,8 +370,8 @@ private function do_commit_post()
}
#$commit_output = preg_replace('/\r?\n\r?/', "<br>\n", $add_output);

if(file_exists('./plugins/peeked/commitresponse.html')) {
$loader = new Twig_Loader_Filesystem('./plugins/peeked');
if(file_exists('./plugins/cms/commitresponse.html')) {
$loader = new Twig_Loader_Filesystem('./plugins/cms');
$twig = new Twig_Environment($loader, array('cache' => null));
$twig->addExtension(new Twig_Extension_Debug());
$twig_vars = array(
Expand All @@ -382,13 +382,13 @@ private function do_commit_post()
$content = $twig->render('commitresponse.html', $twig_vars);
die($content);
} else {
die('Sorry, commitresponse.html was not found in the Peeked plugin. This is an installation problem.');
die('Sorry, commitresponse.html was not found in the backend plugin. This is an installation problem.');
}
}

private function do_pushpull()
{
if(!isset($_SESSION['peeked_logged_in']) || !$_SESSION['peeked_logged_in']) die(json_encode(array('error' => 'Error: Unathorized')));
if(!isset($_SESSION['backend_logged_in']) || !$_SESSION['backend_logged_in']) die(json_encode(array('error' => 'Error: Unathorized')));
if($_SERVER['REQUEST_METHOD'] == 'POST') {
return $this->do_pushpull_post();
}
Expand All @@ -397,7 +397,7 @@ private function do_pushpull()

private function do_pushpull_get()
{
if(file_exists('./plugins/peeked/pushpullform.html')) {
if(file_exists('./plugins/cms/pushpullform.html')) {
# Do the git stuff...
require_once 'Git-php-lib';
$repo = Git::open('.');
Expand All @@ -410,7 +410,7 @@ private function do_pushpull_get()
$remotes = array('Failed to get git sources: ' . $e->getMessage());
}

$loader = new Twig_Loader_Filesystem('./plugins/peeked');
$loader = new Twig_Loader_Filesystem('./plugins/cms');
$twig = new Twig_Environment($loader, array('cache' => null));
$twig->addExtension(new Twig_Extension_Debug());
$twig_vars = array(
Expand All @@ -419,13 +419,13 @@ private function do_pushpull_get()
$content = $twig->render('pushpullform.html', $twig_vars);
die($content);
} else {
die('Sorry, pushpullform.html was not found in the Peeked plugin. This is an installation problem.');
die('Sorry, pushpullform.html was not found in the backend plugin. This is an installation problem.');
}
}

private function do_pushpull_post()
{
if(file_exists('./plugins/peeked/pushpullresponse.html')) {
if(file_exists('./plugins/cms/pushpullresponse.html')) {
# Do the git stuff...
require_once 'Git-php-lib';
$repo = Git::open('.');
Expand Down Expand Up @@ -463,7 +463,7 @@ private function do_pushpull_post()
}

# And do output...
$loader = new Twig_Loader_Filesystem('./plugins/peeked');
$loader = new Twig_Loader_Filesystem('./plugins/cms');
$twig = new Twig_Environment($loader, array('cache' => null));
$twig->addExtension(new Twig_Extension_Debug());
$twig_vars = array(
Expand All @@ -472,12 +472,12 @@ private function do_pushpull_post()
$content = $twig->render('pushpullresponse.html', $twig_vars);
die($content);
} else {
die('Sorry, pushpullresponse.html was not found in the Peeked plugin. This is an installation problem.');
die('Sorry, pushpullresponse.html was not found in the backend plugin. This is an installation problem.');
}
}

private function do_git() {
if(!isset($_SESSION['peeked_logged_in']) || !$_SESSION['peeked_logged_in']) die(json_encode(array('error' => 'Error: Unathorized')));
if(!isset($_SESSION['backend_logged_in']) || !$_SESSION['backend_logged_in']) die(json_encode(array('error' => 'Error: Unathorized')));

$output = array(
'have_git' => 0,
Expand Down
2 changes: 1 addition & 1 deletion commitform.html → cms/commitform.html
Expand Up @@ -32,7 +32,7 @@
<script>
$('#commitform').submit(function(e) {
e.preventDefault();
$.post('peeked/commit', $('#commitform').serialize(), function(data) {
$.post('cms/commit', $('#commitform').serialize(), function(data) {
$('.popupcontent').html(data);
});
});
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions peeked_config.php → cms/config.php
@@ -1,11 +1,11 @@
<?php

global $peeked_password;
global $backend_password;

/*
/*
* This should be a sha1 hash of your password.
* Use a tool like http://www.sha1-online.com to generate.
*/
$peeked_password = '1234567890';
$backend_password = '21cf0cddb652c54cbcaaf1b0bbb2f5a7fe11f39d';

?>

0 comments on commit c7bf8e8

Please sign in to comment.