Coder Social home page Coder Social logo

nliautaud / pico-content-editor Goto Github PK

View Code? Open in Web Editor NEW
15.0 6.0 3.0 359 KB

A WYSIWYG content editor plugin for Pico CMS

License: MIT License

PHP 6.12% JavaScript 84.10% CSS 9.78%
picocms pico-cms editor contenttools metadata-editor pico-plugin plugin

pico-content-editor's Introduction

Pico Content Editor

A WYSIWYG content editor for Pico CMS.

  • live editing with ContentTools
  • save to pages or themes files
  • pages metadata editor
  • images upload
  • authentification with PicoUsers

Demo : https://pico.nliautaud.fr/PicoContentEditor

Installation

Download the repository, name the main folder PicoContentEditor and copy it into the plugins/ directory of your Pico project.

plugins/
    PicoContentEditor/
        src/
        vendor/
        ...

Or, if you installed Pico with composer :

composer require nliautaud/pico-content-editor

Settings

Settings can be defined in the Pico config file, in a page metadata, or both. The page metadata settings will override the site-wide ones.

Every setting is optionnal.

PicoContentEditor:
    show: true          # show/hide the editor
    debug: true         # enable errors reporting
    language: fr        # supported language code
    uploadpath: myfiles # upload directory (images/ by default)
    # custom ContentTools library location (local files by default)
    ContentToolsUrl: https://cdn.jsdelivr.net/npm/ContentTools

The languages supported are listed in the translations/ directory.

Usage

Include the editor files by adding the following tag at the end of your theme, before the closing </body>.

{{ content_editor }}

Define editable regions in your pages by using HTML blocks with the attributes data-editable, data-name and a closing comment end-editable. data-name should be unique accross a single output.

---
Title: A page with editable content
---

The following content is editable :

<div data-editable data-name="pages-first-content">
    <p>Edit me!</p>
</div><!--end editable-->

This one will be converted back to markdown on saving :

<div data-editable data-name="pages-secondary-content" data-markdown markdown=1>
    - One
    - Two
    - Three
</div><!--end editable-->

Every content inside those tags will be editable by visiting the page.

Metadata editor

To add an editor for the pages metadata, use the following tag after the opening of <body> :

{{ content_editor_meta }}

An editable text area will contain the page frontmatter.

Editable regions in themes and templates

You can create editable blocks in themes, just point to the source file with the attribute data-src.

For exemple, the following code could be the content of a footer.twig file in your theme.

<footer id="footer">
    <div data-editable data-name="footer" data-src="themes/mytheme/footer.twig">
        <p>Edit me !</p>
    </div><!--end editable-->
</footer>

Fixed editable elements

To make fixed elements with an editable inner content, use data-fixture instead of data-editable :

<h1 data-fixture data-name="editable-header" data-src="themes/mytheme/header.twig">
Edit me !
</h1><!--end editable-->

Only inline tools will be allowed in this context : Bold, Italic, ...

Unrecognized tags can be defined with data-ce-tag, for example for a fixed editable link and a fixed editable image :

<a data-fixture data-name="my-editable-link" data-ce-tag="p" href="/test">
Editable link
</a><!--end editable-->

<div data-fixture data-name="my-hero-image" data-ce-tag="img-fixture"
     style="background-image: url('image.png');">
    <img src="image.png" alt="Some image">
</div><!--end editable-->

See ContentTools for further info.

Files upload

By default, files uploaded from the editor are saved in an images/ directory located at the root of the Pico installation, next to content/. A custom location can be defined in the settings.

The upload directory should exist and be writeable. The plugin will not create it.

Authentification

If the PicoUsers plugin is installed and detected, actions are automatically restricted to authorized users.

Right Desc
PicoContentEditor All rights below.
PicoContentEditor/save Editing regions in pages and themes source files.
PicoContentEditor/upload Uploading files on the server.

Configuration example of PicoUsers :

users:
    admin: $2y$10$Ym/XYzM9GsCzv3xFTiCea..8.F3xY/BpQISqW6/q3H41SmIK1reZe
    editors:
        bill: $2y$10$INwdOkshW6dhyVJbZYVm1..PxKc1CQTRG5jF.UaynOPDC6aukfkaa
rights:
    PicoContentEditor: admin
    PicoContentEditor/save: editors

pico-content-editor's People

Contributors

nliautaud avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pico-content-editor's Issues

Error replacing region content

Pico CMS and Pico Content Editor installed with Composer on Apache 2 (Ubuntu 18.04).

After editing an editable area and pressing Save button a new result is not saved.
On screen error message is "error replacing region content".

Browser console error message is "Failed to load resource: the server responded with a status of 405 (Method Not Allowed)" or "POST ... Error 405 method not allowed"

Apache config

<Directory /var/www/>
    AllowOverride all
    Require all granted
</Directory>

Pico CMS config

PicoContentEditor:
    show: true          # show/hide the editor
    debug: true         # enable errors reporting

Editable content

<div data-editable data-name="pages-first-content" data-markdown markdown=1>
    Start page
</div><!--end editable-->

Ones more strings from Browser console

PicoContentEditor : SAVE 
Object
regions:
pages-first-content: {markdown: false, html: "<p>↵    Start Page 35564↵</p>"}
__proto__: Object
__proto__: Object

Notifications

Add response notifications. The plugin return a JSON response such as :

{
    "status" : [ { "state": false, "message" : "An error occured" } ]
}

Server-side authentification

Make PicoUser optional, and detect it. If installed do actions only for authorized users.

A setting may be provided to define the authorized users, maybe using PicoUsers rights:

$config['rights'] = array(
    'PicoContentEditor.save' = 'admin'
);

Creating new pages

Is it possible to also create new page? If I have blog or news page, I want users be able to easily create new posts.

vendor/autoload.php is missing

vendor/autoload.php is missing from the repo, but required in PicoContentEditor.php

When I try to install the plugin, I get this error:

{"reqId":"YMK3uXd0L25lwOzRYOkYAQAB8Qk","level":3,"time":"2021-06-11T01:09:19+00:00","remoteAddr":"[IP_ADDRESS]","user":"[USERNAME]","app":"PHP","method":"POST","url":"/index.php/apps/cms_pico/admin/plugins","message":"require(): Failed opening required '/home/[DOMAIN]/www/cloud/apps/cms_pico/appdata_public/plugins/yOv9TEVuUi/PicoContentEditor/vendor/autoload.php' (include_path='/home/[DOMAIN]/www/cloud/apps/mail/vendor/pear-pear.horde.org/Horde_Crypt_Blowfish:/home/[DOMAIN]/www/cloud/apps/mail/vendor/pear-pear.horde.org/Horde_Date:/home/[DOMAIN]/www/cloud/apps/mail/vendor/pear-pear.horde.org/Horde_Exception:/home/[DOMAIN]/www/cloud/apps/mail/vendor/pear-pear.horde.org/Horde_Idna:/home/[DOMAIN]/www/cloud/apps/mail/vendor/pear-pear.horde.org/Horde_Imap_Client:/home/[DOMAIN]/www/cloud/apps/mail/vendor/pear-pear.horde.org/Horde_ListHeaders:/home/[DOMAIN]/www/cloud/apps/mail/vendor/pear-pear.horde.org/Horde_Mail:/home/[DOMAIN]/www/cloud/apps/mail/vendor/pear-pear.horde.org/Horde_ManageSieve:/home/[DOMAIN]/www/cloud/apps/mail/vendor/pear-pear.horde.org/Horde_Mime:/home/[DOMAIN]/www/cloud/apps/mail/vendor/pear-pear.horde.org/Horde_Nls:/home/[DOMAIN]/www/cloud/apps/mail/vendor/pear-pear.horde.org/Horde_Secret:/home/[DOMAIN]/www/cloud/apps/mail at /home/[DOMAIN]/www/cloud/apps/cms_pico/appdata_public/plugins/yOv9TEVuUi/PicoContentEditor/PicoContentEditor.php#2"}

Don't working with pico-users plugin

I added to config

$config['users'] = array(
    'admin' => '???',
    'editors' => array(
        'bill' => '???'
    )
);
$config['rights'] = array(
    'PicoContentEditor' => 'admin',
    'PicoContentEditor/save' => 'editors',
);

added to index.twig

{{ content_editor }}
{{ login_form }}
</body>

Authentitication working, but content_editor with pico users don't working.
I use latest version plugins .

Without pico-users plugin pico-content-editor working correctly.

Save in markdown

If the Markdown Extra attribute markdown=1 is set in a data-editable block, the content is
converted back to Markdown on save.

<div data-editable data-name="pages-first-content" markdown=1>
    - one
    - two
</div><!--end editable-->

500 Error after instalation

For some reason every page returns a 500 Internal Server error after installing PicoContentEditor.

I have cloned the latest version of the repository, renamed the directory PicoContentEditor and changed its ownership to www-data. I am using the pagination, search, and users plugins. They work on their own, but not with the Content Editor.

I found that the errors are seemingly because the __DIR__ variable is being used to find PicoCMS's directory, but is instead returning PCE's directory

Editable blocks in theme

What would be the best way to support editable blocks in theme ?

In themes, editable blocks may be located in included files, so their origin have to be determined.

Maybe :

  1. a editable-src="path/file.twig" attribute in blocks that would provide a relative path
  2. instead of looking in the page rawcontent, search for all editable blocks in the final HTML output, and for each
  3. target the given editable-src file, or the current page if not provided
  4. if target file exists, look for the named block and replace content if found
  5. save target if changed

Image upload not working

Great plugin, thank you for sharing.

I have installed the editor and all seems good except uploading images. they get uploaded to the images folder, but cannot insert them into content.

Have tried on Pico V1 and the 2 beta with same results. Running PHP 7.2.1

Here is the logs from console and any suggestions to solve much appreciated:

File(13539) {name: "avatar04.png", lastModified: 1499535957000, lastModifiedDate: Sat Jul 08 2017 12:45:57 GMT-0500 (Central Daylight Time), webkitRelativePath: "", size: 13539, …}lastModified: 1499535957000lastModifiedDate: Sat Jul 08 2017 12:45:57 GMT-0500 (Central Daylight Time) {}name: "avatar04.png"size: 13539type: "image/png"webkitRelativePath: ""__proto__: File


Uncaught TypeError: Cannot read property 'path' of undefined
    at XMLHttpRequest.xhrComplete (editor.js:73)
	
	
xhrComplete @ editor.js:73
XMLHttpRequest.send (async)
(anonymous) @ editor.js:104
a.dispatchEvent @ content-tools.min.js:4
(anonymous) @ content-tools.min.js:5

Blocks parser

For now the editable blocks are parsed trough regex. That's ugly and not flexible, but it works.

The two main issues are the need of a "ending mark" comment <!--end editable-->, and the rigidity of supported attributes.

To use a proper HTML parser, we'd need to find how to replace a specific zone (or node content) without altering any outer content, even if it's not proper html. It would be the parser job to return the full content with localized changes, but the tried parsers, when given non-html content (ex. markdown) were altering unknown parts.

An alternative would be to keep regex but get rid of html blocks, and use custom tags or twig functions, but it would add a layer between the user and ContentTools that may be worse.

Compatible with PicoCMS 2.1.4?

I manually installed PicoCMS v2.1.4 and figured out how to create .md home page and sub pages. Then I downloaded and manually moved PicoContentEditor to /plugins where it is the only plugin besides PicoDeprecated. I immediately ran into problems with nothing showing on pages and an indication of 500 Internal Server Error. When I removed the PCE plugin, the pages started working again.

I noticed that PicoContentEditor.php is using API v2, while it looks like Pico v2.1.x uses API v3. I tried editing PCE.php to use v3, but that did not make any difference--the pages were still blank. Is PCE compatible with Pico v2.1.4?

Thanks,
Tim

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.