-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "elvendor/imgjss", | ||
"description": "", | ||
"authors": [ | ||
{ | ||
"name": "Elvendod", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.4.0", | ||
"illuminate/support": "4.2.*" | ||
}, | ||
"autoload": { | ||
"psr-0": { | ||
"Elvendor\\Imgjss\\": "src/" | ||
} | ||
}, | ||
"minimum-stability": "stable" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php namespace Elvendor\Imgjss; | ||
|
||
use Illuminate\Support\ServiceProvider, | ||
Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
|
||
class ImgjssServiceProvider extends ServiceProvider | ||
{ | ||
|
||
/** | ||
* Indicates if loading of the provider is deferred. | ||
* | ||
* @var bool | ||
*/ | ||
protected $defer = false; | ||
|
||
/** | ||
* Bootstrap the application events. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
$this->package('elvendor/imgjss'); | ||
|
||
$app = $this->app; | ||
$blade = $app['blade.compiler']; | ||
$html = $app['html']; | ||
|
||
$html->macro('css', function($path, $attrs = [], $timestamp = null, $secure = null) use($app) | ||
{ | ||
return $app['html']->style($this->process($path, '.css', $timestamp), $attrs, $secure); | ||
}); | ||
|
||
$html->macro('js', function($path, $attrs = [], $timestamp = null, $secure = null) use($app) | ||
{ | ||
return $app['html']->script($this->process($path, '.js', $timestamp), $attrs, $secure); | ||
}); | ||
|
||
$html->macro('img', function($path, $attrs = [], $timestamp = null, $secure = null) use($app) | ||
{ | ||
return $app['html']->image($this->process($path, null, $timestamp), @$attrs['alt'] ? $attrs['alt'] : null, $attrs, $secure); | ||
}); | ||
|
||
$blade->extend(function($view) use($html) | ||
{ | ||
return preg_replace("/@css(.*)/", "<?php echo HTML::css$1;?>", $view); | ||
}); | ||
|
||
$blade->extend(function($view) use($html) | ||
{ | ||
return preg_replace("/@js(.*)/", "<?php echo HTML::js$1;?>", $view); | ||
}); | ||
|
||
$blade->extend(function($view) use($html) | ||
{ | ||
return preg_replace("/@img(.*)/", "<?php echo HTML::img$1 . '\r\n';?>", $view); | ||
}); | ||
|
||
} | ||
|
||
public function process($path, $ext = null, $timestamp = null) | ||
{ | ||
|
||
$app = $this->app; | ||
$config = $app['config']->get('imgjss::config'); | ||
|
||
if($ext !== null && $ext !== strrchr($path, ".")) | ||
{ | ||
$path .= $ext; | ||
} | ||
|
||
// Get the full path to the asset. | ||
$absolutePath = public_path($path); | ||
|
||
if (!file_exists($absolutePath)) | ||
{ | ||
throw new NotFoundHttpException('Asset not found: ' . $path); | ||
} | ||
|
||
$timestamp = !is_null($timestamp) ? $timestamp : $config['timestamp']; | ||
|
||
return $timestamp ? $path . $config['qstring'] . filemtime($absolutePath) : $path; | ||
|
||
} | ||
|
||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Get the services provided by the provider. | ||
* | ||
* @return array | ||
*/ | ||
public function provides() | ||
{ | ||
return array(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
/** | ||
* Add timestamp by default | ||
*/ | ||
'timestamp' => false, | ||
|
||
'qstring' => '?t=' | ||
]; |