Skip to content

Commit

Permalink
Merge pull request #1 from immanuelfodor/slim-v0.12.0-beta
Browse files Browse the repository at this point in the history
Compatibility with Shaarli v0.12.0-beta
  • Loading branch information
immanuelfodor authored Aug 30, 2020
2 parents 1991177 + b20ce52 commit eca7f12
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 30 deletions.
44 changes: 25 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,53 @@
# Shaarli Plugin Emojione

Add colorful emojis to your Shaarli.

# Installation
```
## Installation

```bash
cd plugins
git clone https://github.com/NerosTie/emojione
git clone https://github.com/immanuelfodor/emojione.git
```

Or download [the zip archive](https://github.com/NerosTie/emojione/archive/master.zip) and extract it in `plugins/emojione`.
Or download the zip archive and extract it in `plugins/emojione`.

Then activate the new plugin.

# Options
## Options

ASCII Smiley is deactivated by default.
http://git.emojione.com/demos/latest/ascii-smileys.html
To activate it, edit `assets/js/emojione.js`:
```

```javascript
emojione.ascii = false; /* change to 'true' to have ASCII conversion */
```
SVG is the default format for emojis.
If you prefer PNG, edit `assets/js/emojione.js`:
```

SVG is the default format for emojis. If you prefer PNG, edit `assets/js/emojione.js`:

```javascript
emojione.imageType = 'svg'; /* change to 'png' to have emojis in PNG */
```

The autocomplete function is deactivated by default.
The autocomplete function is activated by default.
http://git.emojione.com/demos/latest/autocomplete.html
To activate it, edit `emojione.php`:
```
To deactivate it, edit `emojione.php`:

```php
/*
* Uncomment the five lines below to use the autocomplete function.
* If your theme use jquery, let the second line commented.
* Comment the five lines below to disable the autocomplete function.
* If your theme use jquery, you must comment the jquery.min.js line to avoid conflicts.
*/
# if($data['_PAGE_'] === Router::$PAGE_EDITLINK){
# if (eo_strip_underscores($data['_PAGE_']) == eo_strip_underscores($router::$PAGE_EDITLINK)) {
# $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/emojione/assets/js/jquery.min.js';
# $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/emojione/assets/js/textcomplete.min.js';
# $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/emojione/assets/js/autocomplete.js';
# }
```

# Compatibility
## Compatibility

The plugin and the options are fully compatible with these themes:
* Default
* Material (https://github.com/kalvn/Shaarli-Material)
* AlbinoMouse (https://github.com/alexisju/albinomouse-template)
- Default
- Material (https://github.com/kalvn/Shaarli-Material)
- AlbinoMouse (https://github.com/alexisju/albinomouse-template) - Untested in this fork
2 changes: 1 addition & 1 deletion assets/js/autocomplete.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions assets/js/emojione.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var posts = document.querySelectorAll('.link-tag, .link-description, .link-title, a, p, .dailyEntryTags');
emojione.ascii = false; /* change to 'true' to have ASCII conversion */
emojione.imageType = 'svg'; /* change to 'png' to have emojis in PNG */
emojione.imagePathSVG = "../plugins/emojione/assets/svg/";
emojione.imagePathPNG = "../plugins/emojione/assets/png/";
emojione.imagePathSVG = "/plugins/emojione/assets/svg/";
emojione.imagePathPNG = "/plugins/emojione/assets/png/";
Array.prototype.forEach.call(posts, function(el, i){
var parsed = emojione.toImage(el.innerHTML);
el.innerHTML = parsed;
Expand Down
63 changes: 55 additions & 8 deletions emojione.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,54 @@
<?php

use Shaarli\Router;
use Shaarli\Legacy\LegacyRouter;
use Shaarli\Plugin\PluginManager;

/**
* Strip underscores from routes to maintain compatibility between old
* and new Shaarlies after the Slim rewrite.
*
* @see: https://github.com/shaarli/Shaarli/pull/1511#issuecomment-683393764
*
* @param string $route - the route as string
*
* @return string - the route without underscores
*/
function eo_strip_underscores($route)
{
return str_replace('_', '', $route);
}

/**
* Get the available Shaarli router class.
* Keeps compatibility with older Shaarlies besides supporting the new Slim rewrite.
*
* @see: https://github.com/shaarli/Shaarli/pull/1511
* @see: https://github.com/ilesinge/shaarli-related/pull/4/files
*
* @return string - the namespaced router class name
*/
function eo_get_router()
{
/** introduced with the Slim rewrite of the recent Shaarli */
$newShaarliRouter = 'Shaarli\Legacy\LegacyRouter';
/** original router class of old Shaarlies */
$oldShaarliRouter = 'Shaarli\Router';

if (class_exists($newShaarliRouter)) {
return $newShaarliRouter;
}

return $oldShaarliRouter;
}

function hook_emojione_render_includes($data)
{
$router = eo_get_router();

$data['css_files'][] = PluginManager::$PLUGINS_PATH . '/emojione/assets/css/emojione.css';

if($data['_PAGE_'] === Router::$PAGE_EDITLINK){
if (eo_strip_underscores($data['_PAGE_']) == eo_strip_underscores($router::$PAGE_EDITLINK)) {
$data['css_files'][] = PluginManager::$PLUGINS_PATH . '/emojione/assets/css/autocomplete.css';
}

Expand All @@ -12,15 +57,17 @@ function hook_emojione_render_includes($data)

function hook_emojione_render_footer($data)
{
$router = eo_get_router();

/*
* Uncomment the five lines below to use the autocomplete function.
* If your theme use jquery, let the second line commented.
* Comment the five lines below to disable the autocomplete function.
* If your theme use jquery, you must comment the jquery.min.js line to avoid conflicts.
*/
# if($data['_PAGE_'] === Router::$PAGE_EDITLINK){
# $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/emojione/assets/js/jquery.min.js';
# $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/emojione/assets/js/textcomplete.min.js';
# $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/emojione/assets/js/autocomplete.js';
# }
if (eo_strip_underscores($data['_PAGE_']) == eo_strip_underscores($router::$PAGE_EDITLINK)) {
$data['js_files'][] = PluginManager::$PLUGINS_PATH . '/emojione/assets/js/jquery.min.js';
$data['js_files'][] = PluginManager::$PLUGINS_PATH . '/emojione/assets/js/textcomplete.min.js';
$data['js_files'][] = PluginManager::$PLUGINS_PATH . '/emojione/assets/js/autocomplete.js';
}

$data['js_files'][] = PluginManager::$PLUGINS_PATH . '/emojione/assets/js/emojione.min.js';
$data['js_files'][] = PluginManager::$PLUGINS_PATH . '/emojione/assets/js/unicode.js';
Expand Down

0 comments on commit eca7f12

Please sign in to comment.