2014-10-14 21:09:46 +00:00
|
|
|
<?php namespace System\Classes;
|
|
|
|
|
|
2015-02-23 08:55:06 +00:00
|
|
|
use Lang;
|
2020-08-08 05:27:32 +00:00
|
|
|
use Response;
|
|
|
|
|
use Exception;
|
|
|
|
|
use SystemException;
|
2015-01-28 07:03:35 +00:00
|
|
|
use ApplicationException;
|
2015-02-23 08:55:06 +00:00
|
|
|
use Illuminate\Routing\Controller as ControllerBase;
|
2014-10-14 21:09:46 +00:00
|
|
|
|
|
|
|
|
/**
|
2017-03-16 06:08:20 +00:00
|
|
|
* The is the master controller for system related routing.
|
|
|
|
|
* It is currently only responsible for serving up the asset combiner contents.
|
2014-10-14 21:09:46 +00:00
|
|
|
*
|
2017-03-16 06:08:20 +00:00
|
|
|
* @see System\Classes\CombineAssets Asset combiner class
|
2014-10-14 21:09:46 +00:00
|
|
|
* @package october\system
|
2020-08-08 05:27:32 +00:00
|
|
|
* @author Alexey Bobkov, Samuel Georges, Luke Towers
|
2014-10-14 21:09:46 +00:00
|
|
|
*/
|
2017-03-16 06:08:20 +00:00
|
|
|
class SystemController extends ControllerBase
|
2014-10-14 21:09:46 +00:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Combines JavaScript and StyleSheet assets.
|
|
|
|
|
* @param string $name Combined file code
|
|
|
|
|
* @return string Combined content.
|
|
|
|
|
*/
|
|
|
|
|
public function combine($name)
|
|
|
|
|
{
|
2014-10-18 09:58:50 +00:00
|
|
|
try {
|
|
|
|
|
if (!strpos($name, '-')) {
|
|
|
|
|
throw new ApplicationException(Lang::get('system::lang.combiner.not_found', ['name' => $name]));
|
|
|
|
|
}
|
2014-10-18 23:58:18 +00:00
|
|
|
|
2014-10-18 09:58:50 +00:00
|
|
|
$parts = explode('-', $name);
|
2019-03-28 19:02:06 +00:00
|
|
|
|
2014-10-18 09:58:50 +00:00
|
|
|
$cacheId = $parts[0];
|
2014-10-18 23:58:18 +00:00
|
|
|
|
2015-01-12 09:08:31 +00:00
|
|
|
$combiner = CombineAssets::instance();
|
2014-10-18 23:58:18 +00:00
|
|
|
|
2019-03-28 19:02:06 +00:00
|
|
|
return $combiner->getContents($cacheId);
|
2020-08-08 05:27:32 +00:00
|
|
|
} catch (Exception $ex) {
|
2019-02-27 20:33:48 +00:00
|
|
|
return Response::make('/* '.e($ex->getMessage()).' */', 500);
|
2014-10-18 09:58:50 +00:00
|
|
|
}
|
2014-10-14 21:09:46 +00:00
|
|
|
}
|
2020-08-08 05:27:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Resizes an image using the provided configuration
|
|
|
|
|
* and returns a redirect to the resized image
|
|
|
|
|
*
|
|
|
|
|
* @param string $identifier The identifier used to retrieve the image configuration
|
|
|
|
|
* @return RedirectResponse
|
|
|
|
|
*/
|
2020-08-09 02:18:11 +00:00
|
|
|
public function resizer(string $identifier)
|
2020-08-08 05:27:32 +00:00
|
|
|
{
|
2020-08-09 02:18:11 +00:00
|
|
|
// The URL-encoded URL to the resized image has to be passed as a GET variable
|
|
|
|
|
// because of Laravel rawurldecode's the requested URL before passing it to the routing engine
|
|
|
|
|
// @see https://github.com/laravel/framework/pull/4338
|
|
|
|
|
$encodedUrl = input('t');
|
|
|
|
|
|
|
|
|
|
$resizedUrl = ImageResizer::getValidResizedUrl($identifier, $encodedUrl);
|
|
|
|
|
if (empty($resizedUrl)) {
|
|
|
|
|
return response('Invalid identifier or redirect URL', 400);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-08 05:27:32 +00:00
|
|
|
// Attempt to process the resize
|
|
|
|
|
try {
|
|
|
|
|
$resizer = ImageResizer::fromIdentifier($identifier);
|
|
|
|
|
$resizer->resize();
|
|
|
|
|
} catch (SystemException $ex) {
|
2020-08-09 02:18:11 +00:00
|
|
|
// If the resizing failed it was most likely because it is in progress or has already finished
|
2020-08-08 05:27:32 +00:00
|
|
|
}
|
|
|
|
|
|
2020-08-09 02:18:11 +00:00
|
|
|
return redirect()->to($resizedUrl);
|
2020-08-08 05:27:32 +00:00
|
|
|
}
|
2014-10-18 09:58:50 +00:00
|
|
|
}
|