PHPackages                             caouecs/sirtrevorjs - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. caouecs/sirtrevorjs

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

caouecs/sirtrevorjs
===================

Sir Trevor JS in Laravel project

4.3.2(2y ago)5421.6k↓50%17[1 issues](https://github.com/caouecs/Laravel-SirTrevorJS/issues)MITPHPPHP ^8.0

Since Feb 4Pushed 2y ago4 watchersCompare

[ Source](https://github.com/caouecs/Laravel-SirTrevorJS)[ Packagist](https://packagist.org/packages/caouecs/sirtrevorjs)[ RSS](/packages/caouecs-sirtrevorjs/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (116)Used By (0)

Laravel-SirTrevorJS
===================

[](#laravel-sirtrevorjs)

[![Quality Gate Status](https://camo.githubusercontent.com/7a232d650c5b94a1f0f7a5bcc26e9a4e46728816b9cb62516975a4bb4acc6ed4/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d63616f756563735f4c61726176656c2d536972547265766f724a53266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/dashboard?id=caouecs_Laravel-SirTrevorJS)

Integrate the tool [Sir Trevor JS](http://madebymany.github.io/sir-trevor-js/) in a [Laravel 5/6/7/8/9](http://laravel.com) project.

Installation
------------

[](#installation)

This package is available through `Packagist` and `Composer`.

> **For PHP 8** version, use the [branch master](https://github.com/caouecs/Laravel-SirTrevorJS/tree/master) : `"caouecs/sirtrevorjs": "~4.1.0"`

> **For PHP 7** version, use the [branch v3.0](https://github.com/caouecs/Laravel-SirTrevorJS/tree/v3.0) : `"caouecs/sirtrevorjs": "~3.0.0"`

> **For Laravel &gt;= 5.2** version *parser*, use the [branch v2.5](https://github.com/caouecs/Laravel-SirTrevorJS/tree/2.5) : `"caouecs/sirtrevorjs": "~2.5.0"`

> **For Laravel &gt;= 5.1** version *js &amp; amp*, use the [branch v2.4](https://github.com/caouecs/Laravel-SirTrevorJS/tree/v2.4) : `"caouecs/sirtrevorjs": "~2.4.0"`

> **For Laravel &gt;= 5.1** version *fb articles*, use the [branch v2.3](https://github.com/caouecs/Laravel-SirTrevorJS/tree/v2.3) : `"caouecs/sirtrevorjs": "~2.3.0"`

> **For Laravel &gt;= 5.1** version *view &amp; amp*, use the [branch v2.2](https://github.com/caouecs/Laravel-SirTrevorJS/tree/v2.2) : `"caouecs/sirtrevorjs": "~2.2.0"`

> **For Laravel &gt;= 5.1** version *base*, use the [branch v2.1](https://github.com/caouecs/Laravel-SirTrevorJS/tree/v2.1) : `"caouecs/sirtrevorjs": "~2.1.0"`

> **For Laravel 5.0**, use the [branch v2](https://github.com/caouecs/Laravel-SirTrevorJS/tree/v2) : `"caouecs/sirtrevorjs": "~2.0.0"`

> **For Laravel 4**, use the [branch laravel4](https://github.com/caouecs/Laravel-SirTrevorJS/tree/laravel4) : `"caouecs/sirtrevorjs": "~1.4"`

Please read *README.md* in the choosen branch.

### Service Provider

[](#service-provider)

If you want to use routing, controllers, views, binding directly in your project, in your `app/config/app.php`, add `"Caouecs\Sirtrevorjs\SirtrevorjsServiceProvider"` to your list of providers.

### Twitter

[](#twitter)

To get tweets, this project uses [thujohn/twitter](https://github.com/thujohn/twitter). Please visit the page of the project to know how to install and configure.

Configuration file
------------------

[](#configuration-file)

Next, you must migrate config :

```
php artisan vendor:publish caouecs/sirtrevorjs

```

After installation, the config file is located at *app/config/packages/caouecs/sirtrevorjs/sir-trevor-js.php*.

You can define :

- the path for image upload
- the route for upload image
- the route for tweet
- the path of Sir Trevor files
- the list of block types
- custom blocks
- the language
- the paths for Eventable.js and Underscore.js
- the view
- configuration for blocks
    - soundcloud
    - gettyimages
- etc...

SirTrevorJs class
-----------------

[](#sirtrevorjs-class)

### Assets

[](#assets)

For stylesheets :

```
    SirTrevorJs::stylesheets()
```

For scripts, in your Blade files :

```
    SirTrevorJs::scripts()
```

### Fix for image block

[](#fix-for-image-block)

Function to fix a problem with image block when you add a new image :

```
    string SirTrevorJs::transformText(string $text);
```

### Find first image

[](#find-first-image)

Get first image in text with `findImage` method :

```
    string SirTrevorJS::findImage(string $text);
```

In return, you have url of image or empty string.

### Find elements by blocktypes

[](#find-elements-by-blocktypes)

Get all elements in text, in specified blocktype with `find` method :

```
    mixed SirTrevorJS::find(string $text, string $blocktype [, string $output = "json"])
```

In return, you can have :

- array, if you choose "array" for $output
- json, if you choose "json" for $output
- false, if the script doesn't find an occurence of blocktype

Controller
----------

[](#controller)

### SirTrevorJsable

[](#sirtrevorjsable)

This trait proposes two things :

- upload image where you want
- get tweets

### Upload image

[](#upload-image)

This project proposes a system for upload image, nothing to configure, just the `directory_upload` value in config file.

```
    "directory_upload" => "img/uploads"
```

### Tweet

[](#tweet)

This project proposes a system to get tweets. I use [thujohn/twitter](https://github.com/thujohn/twitter) project.

SirTrevorJsConverter class
--------------------------

[](#sirtrevorjsconverter-class)

This class need a parser, a configuration and a view by default.

You can use the binding of this class :

```
    app('caouecs.sirtrevorjs.converter')
```

### Html

[](#html)

Convert text from Sir Trevor Js to html :

```
    string app('caouecs.sirtrevorjs.converter')->toHtml($text)
```

These methods return a string with html and js codes.

### Amp

[](#amp)

Convert text from Sir Trevor Js to [Amp](https://www.ampproject.org):

```
    string app('caouecs.sirtrevorjs.converter')->toAmp($text);
```

All modules have an amp's version, if it exists an equivalence.

This method returns an array ( *text* and *js*).

### Facebook Instant Articles

[](#facebook-instant-articles)

Convert text from Sir Trevor Js to [Facebook Instant Articles](https://developers.facebook.com/docs/instant-articles/reference):

```
    string app('caouecs.sirtrevorjs.converter')->toFb($text);
```

All modules have an FBArticles's version, if it exists an equivalence.

This method returns a string with html and js codes.

### Adding custom blocks

[](#adding-custom-blocks)

You can choose to add custom blocks in config file or add them by extending SirTrevorJsConverter class.

#### config

[](#config)

```
'customBlocks' => [
    'image_extended' => '\App\SirTrevorConverters\ImageExtendedConverter',
],
```

#### SirTrevorConverter

[](#sirtrevorconverter)

```
