Skip to content

Commit

Permalink
add files
Browse files Browse the repository at this point in the history
  • Loading branch information
creecros committed May 30, 2019
0 parents commit 4afb60e
Show file tree
Hide file tree
Showing 46 changed files with 12,749 additions and 0 deletions.
130 changes: 130 additions & 0 deletions Helper/EmojiTextHelper.php
@@ -0,0 +1,130 @@
<?php

namespace Kanboard\Plugin\EmojiSupport\Helper;

require __DIR__.'/../vendor/emojione/emojione/lib/php/autoload.php';

use Kanboard\Core\Markdown;
use Kanboard\Core\Base;
use Emojione\Client;
use Emojione\RuleSet;


/**
* Text Helpers
*
* @package helper
* @author Frederic Guillot
*/
class EmojiTextHelper extends Base
{
/**
* HTML escaping
*
* @param string $value Value to escape
* @return string
*/
public function e($value)
{
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8', false);
}

/**
* Join with HTML escaping
*
* @param $glue
* @param array $list
* @return string
*/
public function implode($glue, array $list)
{
array_walk($list, function (&$value) { $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8', false); });
return implode($glue, $list);
}

/**
* Markdown transformation
*
* @param string $text
* @param boolean $isPublicLink
* @return string
*/
public function markdown($text, $isPublicLink = false)
{
$emoji = new Client(new Ruleset());
$parser = new Markdown($this->container, $isPublicLink);
$parser->setMarkupEscaped(MARKDOWN_ESCAPE_HTML);
return $emoji->shortnameToImage($parser->text($text));
}

/**
* Format a file size
*
* @param integer $size Size in bytes
* @param integer $precision Precision
* @return string
*/
public function bytes($size, $precision = 2)
{
if ($size == 0) {
return 0;
}

$base = log($size) / log(1024);
$suffixes = array('', 'k', 'M', 'G', 'T');

return round(pow(1024, $base - floor($base)), $precision).$suffixes[(int)floor($base)];
}

/**
* Get the number of bytes from PHP size
*
* @param integer $val PHP size (example: 2M)
* @return integer
*/
public function phpToBytes($val)
{
$size = (int) substr($val, 0, -1);
$last = strtolower(substr($val, -1));

switch ($last) {
case 'g':
$size *= 1024;
case 'm':
$size *= 1024;
case 'k':
$size *= 1024;
}

return $size;
}

/**
* Return true if needle is contained in the haystack
*
* @param string $haystack Haystack
* @param string $needle Needle
* @return boolean
*/
public function contains($haystack, $needle)
{
return strpos($haystack, $needle) !== false;
}

/**
* Return a value from a dictionary
*
* @param mixed $id Key
* @param array $listing Dictionary
* @param string $default_value Value displayed when the key doesn't exists
* @return string
*/
public function in($id, array $listing, $default_value = '?')
{
if (isset($listing[$id])) {
return $this->helper->text->e($listing[$id]);
}

return $default_value;
}
}
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Craig Crosby

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.
42 changes: 42 additions & 0 deletions Plugin.php
@@ -0,0 +1,42 @@
<?php

namespace Kanboard\Plugin\EmojiSupport;

use Kanboard\Core\Plugin\Base;
use Kanboard\Plugin\EmojiSupport\Helper\EmojiTextHelper;


class Plugin extends Base

{
public function initialize()
{
//Helpers
$this->helper->register('text', '\Kanboard\Plugin\EmojiSupport\Helper\EmojiTextHelper');
}

public function getPluginName()
{
return 'EmojiSupport';
}

public function getPluginAuthor()
{
return 'Craig Crosby';
}

public function getPluginVersion()
{
return '1.0.0';
}

public function getPluginDescription()
{
return 'Emoji Support in Markdown for Kanboard';
}

public function getPluginHomepage()
{
return 'https://github.com/creecros/EmojiSupport';
}
}
12 changes: 12 additions & 0 deletions README.md
@@ -0,0 +1,12 @@
[![Latest release](https://img.shields.io/github/release/creecros/EmojiSupport.svg)](https://github.com/creecros/EmojiSupport/releases)
![GitHub license](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/creecros/EmojiSupport/graphs/contributors)
![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)
![Downloads](https://img.shields.io/github/downloads/creecros/EmojiSupport/total.svg)

**:star: If you use it, you should star it on Github!**
*It's the least you can do for all the work put into it!*

# EmojiSupport

Adds Emoji Support to all Markdown in Kanboard!
5 changes: 5 additions & 0 deletions composer.json
@@ -0,0 +1,5 @@
{
"require": {
"emojione/emojione": "^4.5"
}
}
61 changes: 61 additions & 0 deletions composer.lock

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

7 changes: 7 additions & 0 deletions vendor/autoload.php
@@ -0,0 +1,7 @@
<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit65a8882e640840f82a5b23de49691603::getLoader();

0 comments on commit 4afb60e

Please sign in to comment.