From 2507cda94cc89df40ebcb1ef76f6ba13c93046c2 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 29 Oct 2018 15:12:47 +0000 Subject: [PATCH] Normalise classname to remove non alpha chars --- app/Application.php | 10 ++++++++-- app/Helper.php | 10 +++++++++- app/Http/Controllers/ItemController.php | 2 +- app/SupportedApps.php | 6 +++--- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/Application.php b/app/Application.php index 092b5f9f..e6df34e5 100644 --- a/app/Application.php +++ b/app/Application.php @@ -30,7 +30,10 @@ class Application extends Model public function class() { - $class = '\App\SupportedApps\\'.$this->name.'\\'.$this->name; + $name = $this->name; + $name = preg_replace('/\PL/u', '', $name); + + $class = '\App\SupportedApps\\'.$name.'\\'.$name; return $class; } @@ -40,7 +43,10 @@ class Application extends Model $all = self::all(); $list['null'] = 'None'; foreach($all as $app) { - $list['\App\SupportedApps\\'.$app->name.'\\'.$app->name] = $app->name; + $name = $app->name; + $name = preg_replace('/\PL/u', '', $name); + + $list['\App\SupportedApps\\'.$name.'\\'.$name] = $app->name; } return $list; } diff --git a/app/Helper.php b/app/Helper.php index cb973e21..b3b994c7 100644 --- a/app/Helper.php +++ b/app/Helper.php @@ -33,4 +33,12 @@ function title_color($hex) } else { return ' white'; } -} \ No newline at end of file +} + + +function className($name) +{ + $name = preg_replace('/\PL/u', '', $name); + return $name; +} + diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php index b427a3a6..cf077210 100644 --- a/app/Http/Controllers/ItemController.php +++ b/app/Http/Controllers/ItemController.php @@ -352,7 +352,7 @@ class ItemController extends Controller $validapps = []; foreach($list->apps as $app) { $validapps[] = $app->appid; - if(!file_exists(app_path('SupportedApps/'.$app->name))) { + if(!file_exists(app_path('SupportedApps/'.className($app->name)))) { SupportedApps::getFiles($app); $application = new Application; SupportedApps::saveApp($app, $application); diff --git a/app/SupportedApps.php b/app/SupportedApps.php index 852363d0..c278fbab 100644 --- a/app/SupportedApps.php +++ b/app/SupportedApps.php @@ -88,7 +88,7 @@ abstract class SupportedApps mkdir(app_path('SupportedApps'), 0777, true); } - $src = app_path('SupportedApps/'.$app->name.'.zip'); + $src = app_path('SupportedApps/'.className($app->name).'.zip'); file_put_contents($src, $res->getBody()); $zip = new \ZipArchive(); @@ -102,8 +102,8 @@ abstract class SupportedApps public static function saveApp($details, $app) { - $img_src = app_path('SupportedApps/'.$details->name.'/'.$details->icon); - $img_dest = public_path('storage/supportedapps/'.$details->icon); + $img_src = app_path('SupportedApps/'.className($details->name).'/'.$details->icon); + $img_dest = public_path('storage/supportedapps/'.className($details->icon)); //die("i: ".$img_src); copy($img_src, $img_dest);