Commit a1186a7d authored by Joshua Parker's avatar Joshua Parker

Initial commit

parents
.DS_Store
> __Title:__ SimpleMDE
> __Requires__ Release: 0.9.9
> __Tested Up To:__ 0.9.9
> __Requires PHP:__ 7.2+
> __Stable Tag:__ 1.0.3
> __License:__ GPLv3
# Description
A drop-in JavaScript textarea replacement for writing beautiful and understandable Markdown.
# Localization
* English
* Spanish
# Composer Installation (Recommended)
1. Start a new shell session.
2. In the root of your install, run the following command ```composer require parkerj/simplemde```.
# Git Clone Installation
1. Start a shell session and navigate to ```plugins``` folder.
2. Run the following command: ```git clone https://gitlab.gitspace.us/parkerj/simplemde.git simplemde```.
# Zip Installation
1. Download the plugin from the [repository](https://gitlab.gitspace.us/parkerj/simplemde).
2. Log into the backend of your site.
3. Visit Plugins > Add New, and upload the plugin.
4. Please note that if you upload plugins this way from the repository, you need to rename the folder by removing ```-master``` at the end.
# Changelog
## 1.0.3 (2018.09.06)
- Removed namespaced functions
- Refactored
## 1.0.2 (2018.06.13)
- Namespaced functions
\ No newline at end of file
<?php
use TriTan\Common\Hooks\ActionFilterHook as hook;
class SimpleMde
{
/**
* The loader that's responsible for maintaining and registering all hooks that power
* the plugin.
*
* @since 1.0.0
* @access protected
* @var PluginLoader $loader Maintains and registers all hooks for the plugin.
*/
protected $loader;
/**
* The plugin variables container.
*
* @var object $plugin
*/
private $plugin;
/**
* Define the core functionality of the plugin.
*
* @since 1.0.0
*/
public function __construct($plugin)
{
// Define the plugin variables container.
$this->plugin = $plugin;
$this->loadDependencies();
$this->setLocale();
$this->backendHooks();
}
/**
* Load the required dependencies for this plugin.
*
* Include the following files that make up the plugin:
*
* - SimpleMdeActionFilter. Orchestrates the hooks of the plugin.
* - SimpleMdei18n. Defines internationalization functionality.
* - SimpleMdeBackend. Defines all hooks for the admin area.
* - functions. Defines plugin specific functions.
* - syntax-highlighter.router. Defines router and routes for views.
*
* Create an instance of the loader which will be used to register the hooks
* with TriTan CMS.
*
* @since 1.0.0
* @access private
*/
private function loadDependencies()
{
/**
* The class responsible for orchestrating the actions and filters of the
* core plugin.
*/
ttcms_load_file($this->plugin['path'] . 'classes' . DS . 'SimpleMdeActionFilter.php');
/**
* The class responsible for defining internationalization functionality
* of the plugin.
*/
ttcms_load_file($this->plugin['path'] . 'classes' . DS . 'SimpleMdei18n.php');
/**
* The class responsible for defining all actions that occur in the admin area.
*/
ttcms_load_file($this->plugin['path'] . 'classes' . DS . 'SimpleMdeBackend.php');
/**
* Initialize the plugin loader class.
*/
$this->loader = new SimpleMdeActionFilter(hook::getInstance());
}
/**
* Define the locale for this plugin for internationalization.
*
* Uses the SimpleMdei18n class in order to set the domain and to register the hook
* with TriTan CMS.
*
* @since 1.0.0
* @access private
*/
private function setLocale()
{
$plugin_i18n = new SimpleMdei18n($this->plugin);
$this->loader->{'addAction'}('plugins_loaded', $plugin_i18n, 'loadPluginTextdomain');
}
/**
* Register all of the hooks related to the admin area functionality
* of the plugin.
*
* @since 1.0.0
* @access private
*/
private function backendHooks()
{
/**
* Admin
*/
$plugin_admin = new SimpleMdeBackend($this->plugin);
$this->loader->{'addAction'}('init', $plugin_admin, 'overrideDefaultEditor', 5);
// Enqueue the stylesheets.
$this->loader->{'addAction'}('enqueue_ttcms_editor', $plugin_admin, 'enqueueCss', 5);
// Enqueue the scripts.
$this->loader->{'addAction'}('enqueue_ttcms_editor', $plugin_admin, 'enqueueJs', 5);
// Enqueue SimpleMDE.
$this->loader->{'addAction'}('enqueue_ttcms_editor', $plugin_admin, 'enqueueEditor', 5);
}
/**
* Run the loader to execute all of the hooks with TriTan CMS.
*
* @since 1.0.0
*/
public function run()
{
$this->loader->run();
}
}
<?php
use TriTan\Interfaces\Plugin\PluginActionFilterInterface;
use TriTan\Interfaces\Hooks\ActionFilterHookInterface;
/*
* Register all actions and filters for the plugin.
*
* Maintain a list of all hooks that are registered throughout
* the plugin, and register them with the TriTan CMS API. Call the
* run function to execute the list of actions and filters.
*
* @since 1.0.0
*/
class SimpleMdeActionFilter implements PluginActionFilterInterface
{
/**
* The array of actions registered with TriTan CMS.
*
* @since 1.0.0
* @access protected
* @var array $actions The actions registered with TriTan CMS to fire when the plugin loads.
*/
protected $actions;
/**
* The array of filters registered with TriTan CMS.
*
* @since 1.0.0
* @access protected
* @var array $filters The filters registered with TriTan CMS to fire when the plugin loads.
*/
protected $filters;
/**
* Hook object.
*
* @since 1.0.0
* @access protected
* @var object
*/
protected $hook;
/**
* Initialize the collections used to maintain the actions and filters.
*
* @since 1.0.0
*/
public function __construct(ActionFilterHookInterface $hook)
{
$this->actions = [];
$this->filters = [];
$this->hook = $hook;
}
/**
* Add a new action to the collection to be registered with TriTan CMS.
*
* @since 1.0.0
* @param string $hook The name of the TriTan CMS action that is being registered.
* @param object $component A reference to the instance of the object on which the action is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority Optional. he priority at which the function should be fired. Default is 10.
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
*/
public function addAction($hook, $component, $callback, $priority = 10, $accepted_args = 1)
{
$this->actions = $this->add($this->actions, $hook, $component, $callback, $priority, $accepted_args);
}
/**
* Add a new filter to the collection to be registered with TriTan CMS.
*
* @since 1.0.0
* @param string $hook The name of the TriTan CMS filter that is being registered.
* @param object $component A reference to the instance of the object on which the filter is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority Optional. he priority at which the function should be fired. Default is 10.
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1
*/
public function addFilter($hook, $component, $callback, $priority = 10, $accepted_args = 1)
{
$this->filters = $this->add($this->filters, $hook, $component, $callback, $priority, $accepted_args);
}
/**
* A utility function that is used to register the actions and hooks into a single
* collection.
*
* @since 1.0.0
* @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
* @param string $hook The name of the TriTan CMS filter that is being registered.
* @param object $component A reference to the instance of the object on which the filter is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority The priority at which the function should be fired.
* @param int $accepted_args The number of arguments that should be passed to the $callback.
* @return array The collection of actions and filters registered with TriTan CMS.
*/
public function add($hooks, $hook, $component, $callback, $priority, $accepted_args)
{
$hooks[] = [
'hook' => $hook,
'component' => $component,
'callback' => $callback,
'priority' => $priority,
'accepted_args' => $accepted_args
];
return $hooks;
}
/**
* Register the filters and actions with TriTan CMS.
*
* @since 1.0.0
*/
public function run()
{
foreach ($this->filters as $hook) {
$this->hook->{'addFilter'}($hook['hook'], [$hook['component'], $hook['callback']], $hook['priority'], $hook['accepted_args']);
}
foreach ($this->actions as $hook) {
$this->hook->{'addAction'}($hook['hook'], [$hook['component'], $hook['callback']], $hook['priority'], $hook['accepted_args']);
}
}
}
<?php
use TriTan\Common\Hooks\ActionFilterHook;
/*
* The backend functionality of the plugin.
*
* @since 1.0.0
*/
class SimpleMdeBackend
{
/**
* The plugin variables container.
*
* @var object $plugin
*/
private $plugin;
/**
* Construct the class.
*
* @param object $plugin The plugin variables.
*/
public function __construct($plugin)
{
$this->plugin = $plugin;
}
/**
* Register the stylesheets for the backend side of the site.
*
* @since 1.0.0
*/
public function enqueueCss()
{
ttcms_enqueue_css('default', '//cdn.jsdelivr.net/simplemde/latest/simplemde.min.css');
echo '<style>.editor-toolbar.fullscreen, .CodeMirror-fullscreen { z-index: 10000 !important; }</style>' . "\n";
}
/**
* Register the JavaScript for the backend side of the site.
*
* @since 1.0.0
*/
public function enqueueJs()
{
ttcms_enqueue_js('default', '//cdn.jsdelivr.net/simplemde/latest/simplemde.min.js');
}
public function overrideDefaultEditor()
{
ActionFilterHook::getInstance()->{'removeAction'}(
'enqueue_ttcms_editor',
'ttcms_editor',
5
);
}
public function enqueueEditor($selector = null)
{
if ($selector == null) {
$simplemdeId = 'post_content';
} else {
$simplemdeId = $selector;
}
$editor = '
<script async>
var simplemde = new SimpleMDE({
spellChecker: true,
promptURLs: true,
element: document.getElementById("' . $simplemdeId . '"),
toolbar: [
"bold", "italic", "strikethrough", "|",
"heading-1", "heading-2", "heading-3", "|",
"code", "quote", "unordered-list", "ordered-list", "|",
"link", "image",
/*{
name: "insertImage",
action: function (editor) {
this.elFinderBrowser();
}.bind(this),
className: "fa fa-picture-o",
title: "Insert Image",
},*/
"|", "preview", "side-by-side", "fullscreen",
{
name: "guide",
action: function () {
$("#guide").modal("show");
},
className: "fa fa-question-circle",
title: "Markdown Guide"
}
]
});
</script>
<div class="modal" id="guide">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">' . t__('Markdown Guide', $this->plugin['id']) . '</h4>
</div>
<div class="modal-body">
<h4>Emphasis</h4>
<pre>**<strong>bold</strong>**
*<em>italics</em>*
~~<strike>strikethrough</strike>~~</pre>
<h4>Headers</h4>
<pre># Big header
## Medium header
### Small header
#### Tiny header</pre>
<h4>Lists</h4>
<pre>* Generic list item
* Generic list item
* Generic list item
1. Numbered list item
2. Numbered list item
3. Numbered list item</pre>
<h4>Links</h4>
<pre>[Text to display](http://www.example.com)</pre>
<h4>Quotes</h4>
<pre>&gt; This is a quote.
&gt; It can span multiple lines!</pre>
<h4>Images &nbsp;
<small>Need to upload an image? <a href="http://imgur.com/" target="_blank">Imgur</a> has a great
interface.
</small>
</h4>
<pre>![](http://www.example.com/image.jpg)</pre>
<h4>Tables</h4>
<pre>| Column 1 | Column 2 | Column 3 |
| -------- | -------- | -------- |
| John | Doe | Male |
| Mary | Smith | Female |
<em>Or without aligning the columns...</em>
| Column 1 | Column 2 | Column 3 |
| -------- | -------- | -------- |
| John | Doe | Male |
| Mary | Smith | Female |
</pre>
<h4>Displaying code</h4>
<pre>`var example = "hello!";`
<em>Or spanning multiple lines...</em>
```
var example = "hello!";
alert(example);
```
</pre>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">' . t__('Close', $this->plugin['id']) . '</button>
</div>
</div>
</div>
</div>';
echo ActionFilterHook::getInstance()->{'applyFilter'}('simplemde_editor', $editor, $selector);
}
}
<?php
use TriTan\Common\TextDomain;
use TriTan\Common\Options\Options;
use TriTan\Common\Options\OptionsMapper;
use TriTan\Database;
use TriTan\Common\Context\HelperContext;
use TriTan\Common\Hooks\ActionFilterHook as hook;
use TriTan\Interfaces\Plugin\Plugini18nInterface;
/*
* Define the internationalization functionality.
*
* Loads and defines the internationalization files for this plugin
* so that it is ready for translation.
*
* @since 1.0.0
*/
class SimpleMdei18n implements Plugini18nInterface
{
/**
* The plugin variables container.
*
* @var object $plugin
*/
private $plugin;
protected $domain;
/**
* Construct the class.
*
* @param object $plugin The plugin variables.
*/
public function __construct($plugin)
{
$this->plugin = $plugin;
$this->domain = new TextDomain(
new Options(
new OptionsMapper(
new Database(),
new HelperContext()
)
),
hook::getInstance()
);
}
/**
* Load the plugin text domain for translation.
*
* @since 1.0.0
*/
public function loadPluginTextdomain()
{
$this->domain->{'loadPluginTextDomain'}($this->plugin['id'], $this->plugin['basename'] . DS . 'languages');
}
}
{
"name": "parkerj/simplemde",
"description": "A drop-in JavaScript textarea replacement for writing beautiful and understandable Markdown.",
"type": "tritancms-plugin",
"keywords": ["simplemde","editor","markdown","parsedown"],
"license": "GPL-3.0",
"authors": [
{
"name": "Joshua Parker",
"email": "josh@joshparker.name"
}
],
"require": {
"oomphinc/composer-installers-extender":"1.*",
"erusev/parsedown": "^1.7",
"erusev/parsedown-extra": "^0.7.1"
},
"extra": {
"installer-types": ["tritancms-plugin"]
},
"minimum-stability": "stable",
"prefer-stable": true
}
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "dc8b6333ae16963ababb93d5a6f4f4ac",
"packages": [
{
"name": "erusev/parsedown",
"version": "1.7.1",
"source": {
"type": "git",
"url": "https://github.com/erusev/parsedown.git",
"reference": "92e9c27ba0e74b8b028b111d1b6f956a15c01fc1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/erusev/parsedown/zipball/92e9c27ba0e74b8b028b111d1b6f956a15c01fc1",
"reference": "92e9c27ba0e74b8b028b111d1b6f956a15c01fc1",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35"
},
"type": "library",
"autoload": {
"psr-0": {
"Parsedown": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Emanuil Rusev",
"email": "hello@erusev.com",
"homepage": "http://erusev.com"
}
],
"description": "Parser for Markdown.",
"homepage": "http://parsedown.org",
"keywords": [
"markdown",
"parser"
],
"time": "2018-03-08T01:11:30+00:00"
},
{
"name": "erusev/parsedown-extra",
"version": "0.7.1",
"source": {
"type": "git",
"url": "https://github.com/erusev/parsedown-extra.git",
"reference": "0db5cce7354e4b76f155d092ab5eb3981c21258c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/erusev/parsedown-extra/zipball/0db5cce7354e4b76f155d092ab5eb3981c21258c",
"reference": "0db5cce7354e4b76f155d092ab5eb3981c21258c",
"shasum": ""
},
"require": {
"erusev/parsedown": "~1.4"
},
"type": "library",
"autoload": {
"psr-0": {
"ParsedownExtra": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Emanuil Rusev",
"email": "hello@erusev.com",
"homepage": "http://erusev.com"
}
],
"description": "An extension of Parsedown that adds support for Markdown Extra.",
"homepage": "https://github.com/erusev/parsedown-extra",
"keywords": [
"markdown",
"markdown extra",
"parsedown",
"parser"
],
"time": "2015-11-01T10:19:22+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}
# Translation of SimpleMDE in English
# This file is distributed under the same license as the SimpleMDE package.
msgid ""
msgstr ""
"PO-Revision-Date: 2018-09-02 22:22-0400\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.1.1\n"
"X-Domain: simplemde\n"
"Project-Id-Version: SimpleMDE\n"
"POT-Creation-Date: \n"
"Language-Team: \n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-KeywordsList: __;esc_attr__;esc_html__;t__\n"
"X-Poedit-SourceCharset: UTF-8\n"
"Last-Translator: \n"
"Language: es\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPathExcluded-0: languages\n"
#: classes/SimpleMdeBackend.php:108
msgid "Markdown Guide"
msgstr "Guía de Markdown"
#: classes/SimpleMdeBackend.php:172
msgid "Close"
msgstr "Cerrar"
#: simplemde.plugin.php:17
msgid "SimpleMDE"
msgstr "SimpleMDE"
# Translation of SimpleMDE in English
# This file is distributed under the same license as the SimpleMDE package.
#, fuzzy
msgid ""
msgstr ""
"PO-Revision-Date: +0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Poedit 2.1.1\n"
"X-Domain: simplemde\n"
"Project-Id-Version: SimpleMDE\n"
"POT-Creation-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-KeywordsList: __;esc_attr__;esc_html__;t__\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPathExcluded-0: languages\n"
#: classes/SimpleMdeBackend.php:108
msgid "Markdown Guide"