Repository: christofferok/laravel-emojione Branch: master Commit: d9f8d8ce22b7 Files: 9 Total size: 12.4 KB Directory structure: gitextract_slq4sk2c/ ├── .editorconfig ├── .gitignore ├── LICENSE.md ├── README.md ├── composer.json ├── config/ │ └── emojione.php └── src/ ├── LaravelEmojiOne.php ├── LaravelEmojiOneFacade.php └── LaravelEmojiOneServiceProvider.php ================================================ FILE CONTENTS ================================================ ================================================ FILE: .editorconfig ================================================ ; This file is for unifying the coding style for different editors and IDEs. ; More information at http://editorconfig.org root = true [*] charset = utf-8 indent_size = 4 indent_style = space end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false ================================================ FILE: .gitignore ================================================ /node_modules /vendor composer.lock .DS_Store ================================================ FILE: LICENSE.md ================================================ # The MIT License (MIT) Copyright (c) 2017 Christoffer Korvald > 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. ================================================ FILE: README.md ================================================ # laravel-emojione ❤️ [![Latest Version on Packagist][ico-version]][link-packagist] [![Total Downloads][ico-downloads]][link-downloads] [![Software License][ico-license]](LICENSE.md) 😀 🏋🏼 ❤️ ☮ Laravel package to make it easier working with the gorgeous emojis from [EmojiOne](https://emojione.com/). Remember to read the [EmojiOne Free License](https://www.emojione.com/licenses/free) and provide the appropriate attribution. Or buy a [premium license](https://www.emojione.com/licenses/premium) ## Upgrading from 3.x to 4.x 1. Update your composer dependency to: `"christofferok/laravel-emojione": "^4.0"` and run `composer update` 2. Update `config/emojione.php` (if you have one) with `'emojiVersion' => '4.0'` If you are serving the assets yourself then you need to do the following things: 1. Update your emojione/assets composer dependency to: `"emojione/assets": "^4.0"` and run `composer update` 2. Update `config/emojione.php` with the correct paths and versions 3. Publish the assets again. See "Assets" section further down ## EmojiOne 4.x/3.x vs 2.0 EmojiOne made a lot of changes in their licensing and which resources are provided in the free license. v2 code is still available in the [emojione-v2](https://github.com/christofferok/laravel-emojione/tree/emojione-v2) branch. If you are upgrading this package, be aware that the SVG assets are not available anymore. ## Install Via Composer ``` bash $ composer require christofferok/laravel-emojione ``` __If you are on Laravel 5.4 or lower you need to add the following to your `config/app.php` file:__ Add the ServiceProvider to the providers array in `config/app.php` ``` php ChristofferOK\LaravelEmojiOne\LaravelEmojiOneServiceProvider::class, ``` Add this to the aliases array in `config/app.php` ``` php 'LaravelEmojiOne' => ChristofferOK\LaravelEmojiOne\LaravelEmojiOneFacade::class, ``` Config: ``` bash $ php artisan vendor:publish --tag=config --provider="ChristofferOK\LaravelEmojiOne\LaravelEmojiOneServiceProvider" ``` ## Usage ``` php LaravelEmojiOne::toShort($str); // - native unicode -> shortnames LaravelEmojiOne::shortnameToImage($str); // - shortname -> images LaravelEmojiOne::unicodeToImage($str); // - native unicode -> images LaravelEmojiOne::toImage($str); // - native unicode + shortnames -> images (mixed input) ``` Blade (equivalent to `LaravelEmojiOne::toImage($str)`): `@emojione(':smile:')` -> 😀 `@emojione(':smile: ❤️')` -> 😀❤️ 🚨 The output is not escaped so be careful with what you pass into `@emojione`. More details about how `toImage($str)` works can be found at [https://github.com/Ranks/emojione/blob/master/examples/PHP.md](https://github.com/Ranks/emojione/blob/master/examples/PHP.md) ### Example You want to let users put emoji a comment. When you are saving a comment, you might want to run the content through `LaravelEmojiOne::toShort($str)` to convert `😄` and other emoji to `:smile:` etc. ```php Comment::create([ 'content' => LaravelEmojiOne::toShort(request('content')) ]); ``` So if someone leaves a comment like `This is an awesome comment 😄🔥` it will be saved as `This is an awesome comment :smile: :fire:` In your view where you display your comments you can use ```php @emojione($comment->content) ``` and that will convert `:smile:` and `😄` to the emojione equivalent. ## Assets By default it will use the assets from JSDelivr. Remember to run this before trying to publish any of the assets: ```bash composer require emojione/assets ``` If you want to serve the assets yourself you can publish them with the following commands. Remember to update `config/emojione.php` PNG files in sizes 32/64/128: ``` bash $ php artisan vendor:publish --tag=public --provider="ChristofferOK\LaravelEmojiOne\LaravelEmojiOneServiceProvider" ``` In `config/emojione.php` specify the local path. Remember to specify which size you want in the path (32/64/128). ```php 'imagePathPNG' => '/vendor/emojione/png/64/', ``` ### Sprites If you want to use sprites: ``` bash $ php artisan vendor:publish --tag=sprites --provider="ChristofferOK\LaravelEmojiOne\LaravelEmojiOneServiceProvider" ``` In `config/emojione.php` enable sprites: ```php 'sprites' => true, 'spriteSize' => 32, // 32 or 64 ``` Add the stylesheet to your HTML: ```html ``` ## License Remember to read the [EmojiOne Free License](https://www.emojione.com/developers/free-license) and provide the appropriate attribution. Or buy a [premium license](https://www.emojione.com/developers/premium-license) [ico-version]: https://img.shields.io/packagist/v/christofferok/laravel-emojione.svg?style=flat-square [ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square [ico-travis]: https://img.shields.io/travis/christofferok/laravel-emojione/master.svg?style=flat-square [ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/christofferok/laravel-emojione.svg?style=flat-square [ico-code-quality]: https://img.shields.io/scrutinizer/g/christofferok/laravel-emojione.svg?style=flat-square [ico-downloads]: https://img.shields.io/packagist/dt/christofferok/laravel-emojione.svg?style=flat-square [link-packagist]: https://packagist.org/packages/christofferok/laravel-emojione [link-travis]: https://travis-ci.org/christofferok/laravel-emojione [link-scrutinizer]: https://scrutinizer-ci.com/g/christofferok/laravel-emojione/code-structure [link-code-quality]: https://scrutinizer-ci.com/g/christofferok/laravel-emojione [link-downloads]: https://packagist.org/packages/christofferok/laravel-emojione [link-author]: https://github.com/christofferok ================================================ FILE: composer.json ================================================ { "name": "christofferok/laravel-emojione", "type": "library", "description": "Laravel helper for EmojiOne", "keywords": [ "ChristofferOK", "LaravelEmojiOne", "laravel", "emoji", "emojione" ], "homepage": "https://github.com/christofferok/LaravelEmojiOne", "license": "MIT", "authors": [ { "name": ":Christoffer Korvald", "email": "korvald@gmail.com", "homepage": "https://christofferok.com", "role": "Developer" } ], "require": { "php": "~5.6|~7.0|~8.0", "emojione/emojione": "^4.0.0", "illuminate/support": "~5.1|~6.0|~7.0|~8.0|~9.0" }, "suggest": { "emojione/assets": "If you want to serve the emojione assets yourself" }, "require-dev": { "phpunit/phpunit": "~4.0|~5.0", "squizlabs/php_codesniffer": "^2.3" }, "autoload": { "psr-4": { "ChristofferOK\\LaravelEmojiOne\\": "src" } }, "autoload-dev": { "psr-4": { "ChristofferOK\\LaravelEmojiOne\\": "tests" } }, "scripts": {}, "extra": { "laravel": { "providers": [ "ChristofferOK\\LaravelEmojiOne\\LaravelEmojiOneServiceProvider" ], "aliases": { "LaravelEmojiOne": "ChristofferOK\\LaravelEmojiOne\\LaravelEmojiOneFacade" } } }, "config": { "sort-packages": true } } ================================================ FILE: config/emojione.php ================================================ null, // defaults to jsdelivr's free CDN 'sprites' => false, // use sprites? 'spriteSize' => 32, // 32/64 // If you are using the cdn, then you can change these values to get different sizes 'emojiSize' => 64, // 32/64/128 'emojiVersion' => '4.0', 'ascii' => false, // convert ascii characters into emoji shortcodes ]; ================================================ FILE: src/LaravelEmojiOne.php ================================================ client = new Client(new Ruleset()); $this->client->emojiSize = config('emojione.emojiSize'); $this->client->sprites = config('emojione.sprites'); $this->client->spriteSize = config('emojione.spriteSize'); $this->client->emojiVersion = config('emojione.emojiVersion'); if (config('emojione.imagePathPNG')) { $this->client->imagePathPNG = url(config('emojione.imagePathPNG')) . '/'; } else { // Use the CDN if 'imagePathPNG' config is not set $this->client->imagePathPNG = 'https://cdn.jsdelivr.net/emojione/assets' . '/' . $this->client->emojiVersion . '/png/' . $this->client->emojiSize . '/'; } // config ascii option added ternary incase option isn't part of config $this->client->ascii = config('emojione.ascii') ? true : false; } public function toImage($str) { return $this->client->toImage($str); } public function toShort($str) { return $this->client->toShort($str); } public function shortnameToImage($str) { return $this->client->shortnameToImage($str); } public function unicodeToImage($str) { return $this->client->unicodeToImage($str); } public function getClient() { return $this->client; } } ================================================ FILE: src/LaravelEmojiOneFacade.php ================================================ publishes([__DIR__.'/../config/emojione.php' => config_path('emojione.php')], 'config'); $this->publishes([ base_path('vendor/emojione/assets/png') => public_path('vendor/emojione/png'), ], 'public'); $this->publishes([ base_path('vendor/emojione/assets/sprites') => public_path('vendor/emojione/sprites'), ], 'sprites'); \Blade::directive('emojione', function ($expression) { return "toImage($expression); ?>"; }); } public function register() { $this->mergeConfigFrom(__DIR__.'/../config/emojione.php', 'emojione'); $this->app->singleton(LaravelEmojiOne::class, function (Container $app) { return new LaravelEmojiOne(); }); } }