Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Commit

Permalink
Clean code and rewrite README
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikescops committed Nov 8, 2018
1 parent ce23b35 commit b2e458c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 42 deletions.
72 changes: 35 additions & 37 deletions Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,39 @@

class Extension extends BaseExtension
{
public function getName()
{
return "Font Emoticons";
}

public function initialize()
{
if ($this->app['config']->getWhichEnd()=== 'frontend'){
$this->addTwigFunction('emocontent', 'emocontent');

$this->addSnippet('aftercss', '<link rel="stylesheet" type="text/css" href="'. $this->app['paths']['extensions'] .'vendor/mikescops/fontemoticons/css/fontello.css">');
}
}

public function emocontent($content="")
{

$html = $this->smiley($content);

return new \Twig_Markup($html, 'UTF-8');
}

function smiley($content) {
$smiley_array = [' :)', ' :-)', '(-:', '(:', ':smile:', ':(', ':-(', ':sad:',';)', ';-)', ':wink:', ':P', ':-P', ':razz:', '-.-', '-_-', ':sleep:','>:)', '>:-)', ':devil:', ':twisted:',':o', ':-o', ':eek:', '8O', '8o', '8-O', '8-o', ':shock:', ':coffee:', ':D', ':-D', ':grin:','8)', '8-)', 'B)', 'B-)', ':cool:', 'x(', 'x-(', 'X(', 'X-(', ':angry:', 'O:)', '0:)','o:)','O:-)', '0:-)', 'o:-)', ':saint:', ":'(", ":'-(", ':cry:', ':shoot:', '|)', ':squint:', '^^', '^_^', ':lol:', ':/', ':-/', ':beer:'];
$smiley_xhtml = ['happy','happy','happy','happy','happy','unhappy','unhappy','unhappy','wink2','wink2','wink2','tongue','tongue','tongue','sleep','sleep','sleep','devil','devil','devil','devil','surprised','surprised','surprised','surprised','surprised','surprised','surprised','surprised','coffee','grin','grin','grin','sunglasses' ,'sunglasses' ,'sunglasses' ,'sunglasses' ,'sunglasses','angry','angry','angry','angry','angry','saint','saint','saint','saint','saint','saint','saint','cry','cry','cry','shoot','squint','squint','laugh','laugh','laugh','displeased','displeased','beer'];

for ($i = 0; $i<count($smiley_array); $i++)
{
$word = $smiley_array[$i];
$smiley_img = '<i class="icon-emo-' . $smiley_xhtml[$i] . '"></i>';
$content = str_replace($word, $smiley_img, $content);
}
return $content;
}



public function getName()
{
return "Font Emoticons";
}

public function initialize()
{
if ($this->app['config']->getWhichEnd()=== 'frontend'){
$this->addTwigFunction('emocontent', 'emocontent');

$this->addSnippet('aftercss', '<link rel="stylesheet" type="text/css" href="'. $this->app['paths']['extensions'] .'vendor/mikescops/fontemoticons/css/fontello.css">');
}
}

public function emocontent($content="")
{

$html = $this->smiley($content);

return new \Twig_Markup($html, 'UTF-8');
}

function smiley($content) {
$smiley_array = [' :)', ' :-)', '(-:', '(:', ':smile:', ':(', ':-(', ':sad:',';)', ';-)', ':wink:', ':P', ':-P', ':razz:', '-.-', '-_-', ':sleep:','>:)', '>:-)', ':devil:', ':twisted:',':o', ':-o', ':eek:', '8O', '8o', '8-O', '8-o', ':shock:', ':coffee:', ':D', ':-D', ':grin:','8)', '8-)', 'B)', 'B-)', ':cool:', 'x(', 'x-(', 'X(', 'X-(', ':angry:', 'O:)', '0:)','o:)','O:-)', '0:-)', 'o:-)', ':saint:', ":'(", ":'-(", ':cry:', ':shoot:', '|)', ':squint:', '^^', '^_^', ':lol:', ':/', ':-/', ':beer:'];

$smiley_xhtml = ['happy','happy','happy','happy','happy','unhappy','unhappy','unhappy','wink2','wink2','wink2','tongue','tongue','tongue','sleep','sleep','sleep','devil','devil','devil','devil','surprised','surprised','surprised','surprised','surprised','surprised','surprised','surprised','coffee','grin','grin','grin','sunglasses' ,'sunglasses' ,'sunglasses' ,'sunglasses' ,'sunglasses','angry','angry','angry','angry','angry','saint','saint','saint','saint','saint','saint','saint','cry','cry','cry','shoot','squint','squint','laugh','laugh','laugh','displeased','displeased','beer'];

for ($i = 0; $i<count($smiley_array); $i++)
{
$word = $smiley_array[$i];
$smiley_img = '<i class="icon-emo-' . $smiley_xhtml[$i] . '"></i>';
$content = str_replace($word, $smiley_img, $content);
}
return $content;
}
}
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@

The "Font Emoticons" detect smileys in any content and replace it by beautiful icons from Fontello.

Use it by simply placing the following in your template:

{{ emocontent( record.body ) }}

Replace record.body by what you want !
## Install on bolt

Get it on [Bolt MarketPlace](https://market.bolt.cm/) !
Or use the extension manager in your Bolt administration panel.


## How to use

Use it by simply placing the following snippet in your template:


```
{{ emocontent( record.body ) }}
```

Replace `record.body` by what you want !

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "bolt-extension",
"keywords": ["font", "emoticons", "smileys"],
"require": {
"bolt/bolt": ">=2.0.0,<3.0.0"
"bolt/bolt": ">=2.0.0,<4.0.0"
},
"license": "MIT",
"authors": [
Expand Down

0 comments on commit b2e458c

Please sign in to comment.