Browse Source

Normalise classname to remove non alpha chars

pull/282/head
Chris 6 years ago
parent
commit
2507cda94c
  1. 10
      app/Application.php
  2. 10
      app/Helper.php
  3. 2
      app/Http/Controllers/ItemController.php
  4. 6
      app/SupportedApps.php

10
app/Application.php

@ -30,7 +30,10 @@ class Application extends Model
public function class() 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; return $class;
} }
@ -40,7 +43,10 @@ class Application extends Model
$all = self::all(); $all = self::all();
$list['null'] = 'None'; $list['null'] = 'None';
foreach($all as $app) { 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; return $list;
} }

10
app/Helper.php

@ -33,4 +33,12 @@ function title_color($hex)
} else { } else {
return ' white'; return ' white';
} }
} }
function className($name)
{
$name = preg_replace('/\PL/u', '', $name);
return $name;
}

2
app/Http/Controllers/ItemController.php

@ -352,7 +352,7 @@ class ItemController extends Controller
$validapps = []; $validapps = [];
foreach($list->apps as $app) { foreach($list->apps as $app) {
$validapps[] = $app->appid; $validapps[] = $app->appid;
if(!file_exists(app_path('SupportedApps/'.$app->name))) { if(!file_exists(app_path('SupportedApps/'.className($app->name)))) {
SupportedApps::getFiles($app); SupportedApps::getFiles($app);
$application = new Application; $application = new Application;
SupportedApps::saveApp($app, $application); SupportedApps::saveApp($app, $application);

6
app/SupportedApps.php

@ -88,7 +88,7 @@ abstract class SupportedApps
mkdir(app_path('SupportedApps'), 0777, true); 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()); file_put_contents($src, $res->getBody());
$zip = new \ZipArchive(); $zip = new \ZipArchive();
@ -102,8 +102,8 @@ abstract class SupportedApps
public static function saveApp($details, $app) public static function saveApp($details, $app)
{ {
$img_src = app_path('SupportedApps/'.$details->name.'/'.$details->icon); $img_src = app_path('SupportedApps/'.className($details->name).'/'.$details->icon);
$img_dest = public_path('storage/supportedapps/'.$details->icon); $img_dest = public_path('storage/supportedapps/'.className($details->icon));
//die("i: ".$img_src); //die("i: ".$img_src);
copy($img_src, $img_dest); copy($img_src, $img_dest);

Loading…
Cancel
Save