caouecs / sirtrevorjs
Sir Trevor JS in Laravel project
Installs: 20 615
Dependents: 1
Suggesters: 0
Security: 0
Stars: 55
Watchers: 5
Forks: 17
Open Issues: 1
Requires
- php: ^8.0
- illuminate/support: ~9.0|~10.0
- laravelcollective/html: ~6.0
Requires (Dev)
- phpunit/phpunit: ^9.0
- dev-master
- 4.3.2
- 4.3.1
- 4.3.0
- 4.2.1
- 4.2.0
- 4.1.5
- 4.1.4
- 4.1.3
- 4.1.2
- 4.1.1
- 4.1.0
- v4.0.x-dev
- 4.0.2
- 4.0.1
- 4.0.0
- v3.0.x-dev
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.x-dev
- v2.5.x-dev
- 2.5.9
- 2.5.8
- 2.5.7
- 2.5.6
- 2.5.5
- 2.5.4
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- v2.4.x-dev
- 2.4.8
- 2.4.7
- 2.4.5
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- v2.3.x-dev
- 2.3.6
- 2.3.5
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- v2.2.x-dev
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.x-dev
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.4.16
- 1.4.15
- 1.4.14
- 1.4.13
- 1.4.12
- 1.4.11
- 1.4.10
- 1.4.9
- 1.4.8
- 1.4.7
- 1.4.6
- 1.4.5
- 1.4.4
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.1
- 1.3.0
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.11
- 1.1.10
- 1.1.8
- 1.1.5
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-develop
- dev-laravel4
This package is auto-updated.
Last update: 2024-11-07 17:12:08 UTC
README
Integrate the tool Sir Trevor JS in a Laravel 5/6/7/8/9 project.
Installation
This package is available through Packagist
and Composer
.
For PHP 8 version, use the branch master :
"caouecs/sirtrevorjs": "~4.1.0"
For PHP 7 version, use the branch v3.0 :
"caouecs/sirtrevorjs": "~3.0.0"
For Laravel >= 5.2 version parser, use the branch v2.5 :
"caouecs/sirtrevorjs": "~2.5.0"
For Laravel >= 5.1 version js & amp, use theĀ branch v2.4 :
"caouecs/sirtrevorjs": "~2.4.0"
For Laravel >= 5.1 version fb articles, use the branch v2.3 :
"caouecs/sirtrevorjs": "~2.3.0"
For Laravel >= 5.1 version view & amp, use the branch v2.2 :
"caouecs/sirtrevorjs": "~2.2.0"
For Laravel >= 5.1 version base, use the branch v2.1 :
"caouecs/sirtrevorjs": "~2.1.0"
For Laravel 5.0, use the branch v2 :
"caouecs/sirtrevorjs": "~2.0.0"
For Laravel 4, use the branch laravel4 :
"caouecs/sirtrevorjs": "~1.4"
Please read README.md in the choosen branch.
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.
To get tweets, this project uses thujohn/twitter. Please visit the page of the project to know how to install and configure.
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
Assets
For stylesheets :
SirTrevorJs::stylesheets()
For scripts, in your Blade files :
SirTrevorJs::scripts()
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
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
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
SirTrevorJsable
This trait proposes two things :
- upload image where you want
- get tweets
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
This project proposes a system to get tweets. I use thujohn/twitter project.
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
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
Convert text from Sir Trevor Js to Amp:
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
Convert text from Sir Trevor Js to Facebook Instant Articles:
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
You can choose to add custom blocks in config file or add them by extending SirTrevorJsConverter class.
config
'customBlocks' => [ 'image_extended' => '\App\SirTrevorConverters\ImageExtendedConverter', ],
SirTrevorConverter
<?php namespace App\SirTrevorConverters; use \Caouecs\Sirtrevorjs\SirTrevorJsConverter; class SirTrevorJsConverterEditor extends SirTrevorJsConverter { /** * Custom blocks. * * @var array */ protected $customBlocks = [ 'gallery' => '{Your namespace}\\Editor\\Converter\\GalleryConverterEditor', 'readmore' => '{Your namespace}\\Editor\\Converter\\ReadMoreConverterEditor', ]; }
And you need to call this class in your service provider, in register :
$this->app->bind('editor.converter', function ($app) {
return new App\SirTrevorConverters\SirTrevorJsConverterEditor(
new LaravelParser(),
config('sir-trevor-js'),
'html'
);
});
Modules
For the moment, the code can convert :
- blockquote / quote
- embedly card
- facebook post
- getty images
- heading
- iframe
- image
- basic version
- version with caption
- issuu
- sketchfab
- slideshare
- soundcloud
- spotify
- text with Markdown
- tweet
- unordered list
- video
- aol
- canal plus
- daily mail uk
- dailymotion
- france tv
- global news
- livestream
- metacafe
- metatube
- mlb
- nbc bay area
- nhl
- ooyala
- redtube
- ustream (live and recorded)
- veoh
- vevo
- vimeo
- vine
- wat
- yahoo
- youtube
- zoomin.tv
- video with caption