Skip to content

Commit 82c950e

Browse files
committed
First commit.
0 parents  commit 82c950e

8 files changed

+400
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor/

composer.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "petehouston/laravel-tinymce-simple-imageupload",
3+
"description": "Simple image upload for TinyMCE in Laravel.",
4+
"type": "library",
5+
"license": "MIT",
6+
"keywords": [
7+
"laravel",
8+
"laravel 5",
9+
"tinymce",
10+
"image upload",
11+
"php"
12+
],
13+
"homepage": "https://github.com/petehouston/laravel-tinymce-simple-imageupload",
14+
"authors": [
15+
{
16+
"name": "Pete Houston",
17+
"email": "[email protected]",
18+
"homepage": "http://petehouston.com"
19+
}
20+
],
21+
"require": {
22+
"illuminate/support": "~5.1",
23+
"php" : "~5.5|~7.0"
24+
},
25+
"autoload": {
26+
"psr-4": {
27+
"Petehouston\\Tinymce\\": "src"
28+
}
29+
},
30+
}

composer.lock

+235
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/TinymceController.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Petehouston\Tinymce;
4+
5+
use App\Http\Controllers\Controller;
6+
use Illuminate\Http\Request;
7+
8+
class TinymceController extends Controller
9+
{
10+
/**
11+
* Handle image upload from TinyMCE file browser window
12+
*
13+
* @param Request $request
14+
* @return Response
15+
*/
16+
public function uploadImage(Request $request)
17+
{
18+
$image = $request->file('image');
19+
20+
$filename = 'image_'.time().'_'.$image->hashName();
21+
$image = $image->move(public_path('img'), $filename);
22+
23+
return ("
24+
<script>
25+
top.$('.mce-btn.mce-open').parent().find('.mce-textbox').val('/img/".$filename."').closest('.mce-window').find('.mce-primary').click();
26+
</script>
27+
");
28+
}
29+
30+
}

src/TinymceServiceProvider.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Petehouston\Tinymce;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
7+
class TinymceServiceProvider extends ServiceProvider
8+
{
9+
/**
10+
* Indicates if loading of the provider is deferred.
11+
*
12+
* @var bool
13+
*/
14+
protected $defer = false;
15+
16+
/**
17+
* Bootstrap the application events.
18+
*
19+
* @return void
20+
*/
21+
public function boot()
22+
{
23+
// load views
24+
$this->loadViewsFrom(realpath(__DIR__.'/views'), 'mceImageUpload');
25+
26+
// ability to publish view
27+
$this->publishes([
28+
__DIR__.'/views' => resource_path('views/petehouston/tinymce'),
29+
]);
30+
}
31+
32+
/**
33+
* Register the service provider.
34+
*
35+
* @return void
36+
*/
37+
public function register()
38+
{
39+
// load routes
40+
include __DIR__.'/routes.php';
41+
42+
// load controller
43+
$this->app->make('Petehouston\Tinymce\TinymceController');
44+
}
45+
46+
}

src/routes.php

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
Route::post('/tinymce/simple-image-upload', 'Petehouston\Tinymce\TinymceController@uploadImage')->name('tinymce.imageupload');

0 commit comments

Comments
 (0)